diff options
| author | Gerd Moellmann | 2000-07-27 20:06:37 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-07-27 20:06:37 +0000 |
| commit | 77d352a676bf5c4db6755b6f9310a62773e439bb (patch) | |
| tree | 12084619d061563ffd43b7201bfbd3d92d1bcd88 | |
| parent | 9d38d529c186d33262034e38c99a8ce31539c187 (diff) | |
| download | emacs-77d352a676bf5c4db6755b6f9310a62773e439bb.tar.gz emacs-77d352a676bf5c4db6755b6f9310a62773e439bb.zip | |
(sql-ms): Added autoload cookie.
(sql-ingres, sql-solid, sql-mysql, sql-informix, sql-sybase)
(sql-oracle): Ditto.
(sql-help): Doc change.
(sql-mode-oracle-font-lock-keywords): Added PL/SQL keywords, data
types and exceptions.
(sql-placeholder-history): New variable.
(sql-query-placeholders-and-send): New function that will query
the user and replace placeholders with user input.
(sql-oracle): If running on NT, set comint-input-sender to
sql-query-placeholders-and-send.
(sql-stop): If in the SQLi buffer, insert stop notification, else
present it as a message.
(sql-input-ring-separator): Doc change.
(sql-input-ring-file-name): Doc change.
(sql-interactive-mode): Use `sql-input-ring-separator' and
`sql-input-ring-file-name' to set the comint-mode equivalents
without making them local variables.
(sql-stop): Don't bind `sql-input-ring-separator' and
`sql-input-ring-file-name' dynamically to their comint-mode
equivalents.
| -rw-r--r-- | lisp/progmodes/sql.el | 135 |
1 files changed, 83 insertions, 52 deletions
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index 9cb642aaf18..500dd5267df 100644 --- a/lisp/progmodes/sql.el +++ b/lisp/progmodes/sql.el | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | ;; Author: Alex Schroeder <alex@gnu.org> | 5 | ;; Author: Alex Schroeder <alex@gnu.org> |
| 6 | ;; Maintainer: Alex Schroeder <alex@gnu.org> | 6 | ;; Maintainer: Alex Schroeder <alex@gnu.org> |
| 7 | ;; Version: 1.4.13 | 7 | ;; Version: 1.4.16 |
| 8 | ;; Keywords: comm languages processes | 8 | ;; Keywords: comm languages processes |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| @@ -198,8 +198,10 @@ exiting the SQL interpreter in an SQLi buffer will write the input | |||
| 198 | history to the specified file. Starting a new process in a SQLi buffer | 198 | history to the specified file. Starting a new process in a SQLi buffer |
| 199 | will read the input history from the specified file. | 199 | will read the input history from the specified file. |
| 200 | 200 | ||
| 201 | This is used to locally set `comint-input-ring-file-name' when reading | 201 | This is used to initialize `comint-input-ring-file-name'. |
| 202 | or writing the input history." | 202 | |
| 203 | Note that the size of the input history is determined by the variable | ||
| 204 | `comint-input-ring-size'." | ||
| 203 | :type '(choice (const :tag "none" nil) | 205 | :type '(choice (const :tag "none" nil) |
| 204 | (file)) | 206 | (file)) |
| 205 | :group 'SQL) | 207 | :group 'SQL) |
| @@ -211,15 +213,12 @@ If set to \"\\n\", each line in the history file will be interpreted as | |||
| 211 | one command. Multi-line commands are split into several commands when | 213 | one command. Multi-line commands are split into several commands when |
| 212 | the input ring is initialized from a history file. | 214 | the input ring is initialized from a history file. |
| 213 | 215 | ||
| 214 | This variable used to locally set `comint-input-ring-separator' when | 216 | This variable used to initialize `comint-input-ring-separator'. |
| 215 | reading or writing the history file. `comint-input-ring-separator' is | 217 | `comint-input-ring-separator' is part of Emacs 21; if your Emacs |
| 216 | not yet part of Emacs; if your Emacs does not have it, setting | 218 | does not have it, setting `sql-input-ring-separator' will have no |
| 217 | `sql-input-ring-separator' will have no effect. In that case multiline | 219 | effect. In that case multiline commands will be split into several |
| 218 | commands will be split into several commands when the input history is | 220 | commands when the input history is read, as if you had set |
| 219 | read, as if you had set `sql-input-ring-separator' to \"\\n\". | 221 | `sql-input-ring-separator' to \"\\n\"." |
| 220 | |||
| 221 | The source code contains a link to a homepage that might have a patch | ||
| 222 | for comint.el to download." | ||
| 223 | :type 'string | 222 | :type 'string |
| 224 | :group 'SQL) | 223 | :group 'SQL) |
| 225 | 224 | ||
| @@ -405,7 +404,7 @@ Based on `comint-mode-map'.") | |||
| 405 | (define-key map (kbd "C-c C-c") 'sql-send-paragraph) | 404 | (define-key map (kbd "C-c C-c") 'sql-send-paragraph) |
| 406 | (define-key map (kbd "C-c C-r") 'sql-send-region) | 405 | (define-key map (kbd "C-c C-r") 'sql-send-region) |
| 407 | (define-key map (kbd "C-c C-b") 'sql-send-buffer) | 406 | (define-key map (kbd "C-c C-b") 'sql-send-buffer) |
| 408 | (define-key map (kbd "<tab>") 'indent-relative) | 407 | (define-key map (kbd "<TAB>") 'indent-relative) |
| 409 | map) | 408 | map) |
| 410 | "Mode map used for `sql-mode'.") | 409 | "Mode map used for `sql-mode'.") |
| 411 | 410 | ||
| @@ -529,21 +528,31 @@ to add functions and PL/SQL keywords.") | |||
| 529 | "become" "before" "block" "body" "cache" "cancel" "cascade" "change" | 528 | "become" "before" "block" "body" "cache" "cancel" "cascade" "change" |
| 530 | "checkpoint" "compile" "constraint" "constraints" "contents" | 529 | "checkpoint" "compile" "constraint" "constraints" "contents" |
| 531 | "controlfile" "cycle" "database" "datafile" "dba" "disable" "dismount" | 530 | "controlfile" "cycle" "database" "datafile" "dba" "disable" "dismount" |
| 532 | "dump" "each" "enable" "events" "except" "exceptions" "execute" | 531 | "dump" "each" "else" "elsif" "enable" "events" "except" "exceptions" |
| 533 | "explain" "extent" "externally" "flush" "force" "freelist" "freelists" | 532 | "execute" "exit" "explain" "extent" "externally" "false" "flush" "force" |
| 534 | "function" "groups" "including" "initrans" "instance" "layer" "link" | 533 | "freelist" "freelists" "function" "groups" "if" "including" "initrans" |
| 535 | "lists" "logfile" "manage" "manual" "maxdatafiles" "maxinistances" | 534 | "instance" "layer" "link" "lists" "logfile" "loop" "manage" "manual" |
| 536 | "maxlogfiles" "maxloghistory" "maxlogmembers" "maxtrans" "maxvalue" | 535 | "maxdatafiles" "maxinistances" "maxlogfiles" "maxloghistory" |
| 537 | "minextents" "minvalue" "mount" "new" "next" "noarchivelog" "nocache" | 536 | "maxlogmembers" "maxtrans" "maxvalue" "minextents" "minvalue" "mount" |
| 538 | "nocycle" "nomaxvalue" "nominvalue" "none" "noorder" "noresetlogs" | 537 | "new" "next" "noarchivelog" "nocache" "nocycle" "nomaxvalue" |
| 539 | "normal" "nosort" "off" "old" "only" "optimal" "own" "package" | 538 | "nominvalue" "none" "noorder" "noresetlogs" "normal" "nosort" "off" |
| 540 | "parallel" "pctincrease" "pctused" "plan" "private" "profile" "quota" | 539 | "old" "only" "optimal" "others" "out" "own" "package" "parallel" |
| 541 | "read" "recover" "referencing" "resetlogs" "restricted" "reuse" "role" | 540 | "pctincrease" "pctused" "plan" "pragma" "private" "profile" "quota" |
| 542 | "roles" "savepoint" "scn" "segment" "sequence" "shared" "snapshot" | 541 | "raise" "read" "recover" "referencing" "resetlogs" "restrict_references" |
| 543 | "sort" "statement_id" "statistics" "stop" "storage" "switch" "system" | 542 | "restricted" "return" "returning" "reuse" "rnds" "rnps" "role" "roles" |
| 543 | "savepoint" "scn" "segment" "sequence" "shared" "snapshot" "sort" | ||
| 544 | "statement_id" "statistics" "stop" "storage" "subtype" "switch" "system" | ||
| 544 | "tables" "tablespace" "temporary" "thread" "time" "tracing" | 545 | "tables" "tablespace" "temporary" "thread" "time" "tracing" |
| 545 | "transaction" "triggers" "truncate" "under" "unlimited" "until" "use" | 546 | "transaction" "triggers" "true" "truncate" "type" "under" "unlimited" |
| 546 | "using" "when" "write") t) "\\b"))) | 547 | "until" "use" "using" "when" "while" "wnds" "wnps" "write") t) "\\b"))) |
| 548 | (oracle-warning-words (eval-when-compile | ||
| 549 | (concat "\\b" | ||
| 550 | (regexp-opt '( | ||
| 551 | "cursor_already_open" "dup_val_on_index" "exception" "invalid_cursor" | ||
| 552 | "invalid_number" "login_denied" "no_data_found" "not_logged_on" | ||
| 553 | "notfound" "others" "pragma" "program_error" "storage_error" | ||
| 554 | "timeout_on_resource" "too_many_rows" "transaction_backed_out" | ||
| 555 | "value_error" "zero_divide") t) "\\b"))) | ||
| 547 | (oracle-reserved-words (eval-when-compile | 556 | (oracle-reserved-words (eval-when-compile |
| 548 | (concat "\\b" | 557 | (concat "\\b" |
| 549 | (regexp-opt '( | 558 | (regexp-opt '( |
| @@ -560,7 +569,8 @@ to add functions and PL/SQL keywords.") | |||
| 560 | (regexp-opt '( | 569 | (regexp-opt '( |
| 561 | ;; Oracle Keywords that look like types | 570 | ;; Oracle Keywords that look like types |
| 562 | ;; Oracle Reserved Words that look like types | 571 | ;; Oracle Reserved Words that look like types |
| 563 | "date" "decimal" "rowid" "varchar" "varchar2") t) "\\b"))) | 572 | "binary_integer" "blob" "boolean" "constant" "date" "decimal" "rowid" |
| 573 | "varchar" "varchar2") t) "\\b"))) | ||
| 564 | (oracle-builtin-functions (eval-when-compile | 574 | (oracle-builtin-functions (eval-when-compile |
| 565 | (concat "\\b" | 575 | (concat "\\b" |
| 566 | (regexp-opt '( | 576 | (regexp-opt '( |
| @@ -575,10 +585,11 @@ to add functions and PL/SQL keywords.") | |||
| 575 | "rtrim" "sign" "sin" "sinh" "soundex" "sqlcode" "sqlerrm" "sqrt" | 585 | "rtrim" "sign" "sin" "sinh" "soundex" "sqlcode" "sqlerrm" "sqrt" |
| 576 | "stddev" "sum" "substr" "substrb" "tan" "tanh" "to_char" | 586 | "stddev" "sum" "substr" "substrb" "tan" "tanh" "to_char" |
| 577 | "to_date" "to_label" "to_multi_byte" "to_number" "to_single_byte" | 587 | "to_date" "to_label" "to_multi_byte" "to_number" "to_single_byte" |
| 578 | "translate" "trunc" "uid" "upper" "userenv" "variance" "vsize") t) "\\b")))) | 588 | "translate" "trim" "trunc" "uid" "upper" "userenv" "variance" "vsize") t) "\\b")))) |
| 579 | (setq sql-mode-oracle-font-lock-keywords | 589 | (setq sql-mode-oracle-font-lock-keywords |
| 580 | (append sql-mode-ansi-font-lock-keywords | 590 | (append sql-mode-ansi-font-lock-keywords |
| 581 | (list (cons oracle-keywords 'font-lock-function-name-face) | 591 | (list (cons oracle-keywords 'font-lock-function-name-face) |
| 592 | (cons oracle-warning-words 'font-lock-warning-face) | ||
| 582 | (cons oracle-reserved-words 'font-lock-keyword-face) | 593 | (cons oracle-reserved-words 'font-lock-keyword-face) |
| 583 | ;; XEmacs doesn't have font-lock-builtin-face | 594 | ;; XEmacs doesn't have font-lock-builtin-face |
| 584 | (if (string-match "XEmacs\\|Lucid" emacs-version) | 595 | (if (string-match "XEmacs\\|Lucid" emacs-version) |
| @@ -701,11 +712,6 @@ buffer. The output generated is appended to the buffer and a new prompt | |||
| 701 | is generated. See the In/Out menu in the SQLi buffer for some functions | 712 | is generated. See the In/Out menu in the SQLi buffer for some functions |
| 702 | that help you navigate through the buffer, the input history, etc. | 713 | that help you navigate through the buffer, the input history, etc. |
| 703 | 714 | ||
| 704 | Put a line with a call to autoload into your `~/.emacs' file for each | ||
| 705 | entry function you want to use regularly: | ||
| 706 | |||
| 707 | \(autoload 'sql-postgres \"sql\" \"Interactive SQL mode.\" t) | ||
| 708 | |||
| 709 | If you have a really complex SQL statement or if you are writing a | 715 | If you have a really complex SQL statement or if you are writing a |
| 710 | procedure, you can do this in a separate buffer. Put the new buffer in | 716 | procedure, you can do this in a separate buffer. Put the new buffer in |
| 711 | `sql-mode' by calling \\[sql-mode]. The name of this buffer can be | 717 | `sql-mode' by calling \\[sql-mode]. The name of this buffer can be |
| @@ -898,6 +904,27 @@ Inserts SELECT or commas if appropriate." | |||
| 898 | (insert column) | 904 | (insert column) |
| 899 | (message "%s" column)))) | 905 | (message "%s" column)))) |
| 900 | 906 | ||
| 907 | ;; On NT, SQL*Plus for Oracle turns on full buffering for stdout if it | ||
| 908 | ;; is not attached to a character device; therefore placeholder | ||
| 909 | ;; replacement by SQL*Plus is fully buffered. The workaround lets | ||
| 910 | ;; Emacs query for the placeholders. | ||
| 911 | |||
| 912 | (defvar sql-placeholder-history nil | ||
| 913 | "History of placeholder values used.") | ||
| 914 | |||
| 915 | (defun sql-query-placeholders-and-send (proc string) | ||
| 916 | "Send to PROC input STRING, maybe replacing placeholders. | ||
| 917 | Placeholders are words starting with and ampersand like &this. | ||
| 918 | This function is used for `comint-input-sender' if using `sql-oracle' on NT." | ||
| 919 | (while (string-match "&\\(\\sw+\\)" string) | ||
| 920 | (setq string (replace-match | ||
| 921 | (read-from-minibuffer | ||
| 922 | (format "Enter value for %s: " (match-string 1 string)) | ||
| 923 | nil nil nil sql-placeholder-history) | ||
| 924 | t t string))) | ||
| 925 | (comint-send-string proc string) | ||
| 926 | (comint-send-string proc "\n")) | ||
| 927 | |||
| 901 | 928 | ||
| 902 | 929 | ||
| 903 | ;;; Sending the region to the SQLi buffer. | 930 | ;;; Sending the region to the SQLi buffer. |
| @@ -1058,8 +1085,7 @@ interpreter output, the hooks on `comint-output-filter-functions' are | |||
| 1058 | run. | 1085 | run. |
| 1059 | 1086 | ||
| 1060 | Variable `sql-input-ring-file-name' controls the initialisation of the | 1087 | Variable `sql-input-ring-file-name' controls the initialisation of the |
| 1061 | input ring history. `comint-input-ring-file-name' is temporarily bound | 1088 | input ring history. |
| 1062 | to `sql-input-ring-file-name' when reading the input history. | ||
| 1063 | 1089 | ||
| 1064 | Variables `comint-output-filter-functions', a hook, and | 1090 | Variables `comint-output-filter-functions', a hook, and |
| 1065 | `comint-scroll-to-bottom-on-input' and | 1091 | `comint-scroll-to-bottom-on-input' and |
| @@ -1105,11 +1131,11 @@ you entered, right above the output it created. | |||
| 1105 | (setq abbrev-all-caps 1) | 1131 | (setq abbrev-all-caps 1) |
| 1106 | ;; Exiting the process will call sql-stop. | 1132 | ;; Exiting the process will call sql-stop. |
| 1107 | (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop) | 1133 | (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop) |
| 1108 | ;; Make input-ring stuff buffer local so that people who want a | 1134 | ;; People wanting a different history file for each |
| 1109 | ;; different history file for each buffer/process/client/whatever can | 1135 | ;; buffer/process/client/whatever can change separator and file-name |
| 1110 | ;; change separator and file-name on the sql-interactive-mode-hook. | 1136 | ;; on the sql-interactive-mode-hook. |
| 1111 | (make-local-variable 'sql-input-ring-separator) | 1137 | (setq comint-input-ring-separator sql-input-ring-separator |
| 1112 | (make-local-variable 'sql-input-ring-file-name) | 1138 | comint-input-ring-file-name sql-input-ring-file-name) |
| 1113 | ;; Create a usefull name for renaming this buffer later. | 1139 | ;; Create a usefull name for renaming this buffer later. |
| 1114 | (make-local-variable 'sql-alternate-buffer-name) | 1140 | (make-local-variable 'sql-alternate-buffer-name) |
| 1115 | (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name)) | 1141 | (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name)) |
| @@ -1117,10 +1143,7 @@ you entered, right above the output it created. | |||
| 1117 | (run-hooks 'sql-interactive-mode-hook) | 1143 | (run-hooks 'sql-interactive-mode-hook) |
| 1118 | ;; Calling the hook before calling comint-read-input-ring allows users | 1144 | ;; Calling the hook before calling comint-read-input-ring allows users |
| 1119 | ;; to set comint-input-ring-file-name in sql-interactive-mode-hook. | 1145 | ;; to set comint-input-ring-file-name in sql-interactive-mode-hook. |
| 1120 | ;; While reading the history, file-name and history are rebound... | 1146 | (comint-read-input-ring t)) |
| 1121 | (let ((comint-input-ring-file-name sql-input-ring-file-name) | ||
| 1122 | (comint-input-ring-separator sql-input-ring-separator)) | ||
| 1123 | (comint-read-input-ring t))) | ||
| 1124 | 1147 | ||
| 1125 | (defun sql-stop (process event) | 1148 | (defun sql-stop (process event) |
| 1126 | "Called when the SQL process is stopped. | 1149 | "Called when the SQL process is stopped. |
| @@ -1132,18 +1155,17 @@ Writes the input history to a history file using | |||
| 1132 | 1155 | ||
| 1133 | This function is a sentinel watching the SQL interpreter process. | 1156 | This function is a sentinel watching the SQL interpreter process. |
| 1134 | Sentinels will always get the two parameters PROCESS and EVENT." | 1157 | Sentinels will always get the two parameters PROCESS and EVENT." |
| 1135 | ;; Write history. | 1158 | (comint-write-input-ring) |
| 1136 | ;; While reading the history, file-name and history are rebound... | 1159 | (if (and (eq (current-buffer) sql-buffer) |
| 1137 | (let ((comint-input-ring-file-name sql-input-ring-file-name) | 1160 | (not buffer-read-only)) |
| 1138 | (comint-input-ring-separator sql-input-ring-separator)) | 1161 | (insert (format "\nProcess %s %s\n" process event)) |
| 1139 | (comint-write-input-ring)) | 1162 | (message "Process %s %s" process event))) |
| 1140 | (if (buffer-live-p sql-buffer) | ||
| 1141 | (insert (format "\nProcess %s %s\n" process event)))) | ||
| 1142 | 1163 | ||
| 1143 | 1164 | ||
| 1144 | 1165 | ||
| 1145 | ;;; Entry functions for different SQL interpreters. | 1166 | ;;; Entry functions for different SQL interpreters. |
| 1146 | 1167 | ||
| 1168 | ;;;###autoload | ||
| 1147 | (defun sql-oracle () | 1169 | (defun sql-oracle () |
| 1148 | "Run sqlplus by Oracle as an inferior process. | 1170 | "Run sqlplus by Oracle as an inferior process. |
| 1149 | 1171 | ||
| @@ -1197,11 +1219,15 @@ The default comes from `process-coding-system-alist' and | |||
| 1197 | ;; calling sql-interactive-mode. | 1219 | ;; calling sql-interactive-mode. |
| 1198 | (setq sql-mode-font-lock-keywords sql-mode-oracle-font-lock-keywords) | 1220 | (setq sql-mode-font-lock-keywords sql-mode-oracle-font-lock-keywords) |
| 1199 | (sql-interactive-mode) | 1221 | (sql-interactive-mode) |
| 1222 | ;; If running on NT, make sure we do placeholder replacement ourselves. | ||
| 1223 | (if (eq window-system 'w32) | ||
| 1224 | (setq comint-input-sender 'sql-query-placeholders-and-send)) | ||
| 1200 | (message "Login...done") | 1225 | (message "Login...done") |
| 1201 | (pop-to-buffer sql-buffer))) | 1226 | (pop-to-buffer sql-buffer))) |
| 1202 | 1227 | ||
| 1203 | 1228 | ||
| 1204 | 1229 | ||
| 1230 | ;;;###autoload | ||
| 1205 | (defun sql-sybase () | 1231 | (defun sql-sybase () |
| 1206 | "Run isql by SyBase as an inferior process. | 1232 | "Run isql by SyBase as an inferior process. |
| 1207 | 1233 | ||
| @@ -1251,6 +1277,7 @@ The default comes from `process-coding-system-alist' and | |||
| 1251 | 1277 | ||
| 1252 | 1278 | ||
| 1253 | 1279 | ||
| 1280 | ;;;###autoload | ||
| 1254 | (defun sql-informix () | 1281 | (defun sql-informix () |
| 1255 | "Run dbaccess by Informix as an inferior process. | 1282 | "Run dbaccess by Informix as an inferior process. |
| 1256 | 1283 | ||
| @@ -1290,6 +1317,7 @@ The default comes from `process-coding-system-alist' and | |||
| 1290 | 1317 | ||
| 1291 | 1318 | ||
| 1292 | 1319 | ||
| 1320 | ;;;###autoload | ||
| 1293 | (defun sql-mysql () | 1321 | (defun sql-mysql () |
| 1294 | "Run mysql by TcX as an inferior process. | 1322 | "Run mysql by TcX as an inferior process. |
| 1295 | 1323 | ||
| @@ -1342,6 +1370,7 @@ The default comes from `process-coding-system-alist' and | |||
| 1342 | 1370 | ||
| 1343 | 1371 | ||
| 1344 | 1372 | ||
| 1373 | ;;;###autoload | ||
| 1345 | (defun sql-solid () | 1374 | (defun sql-solid () |
| 1346 | "Run solsql by Solid as an inferior process. | 1375 | "Run solsql by Solid as an inferior process. |
| 1347 | 1376 | ||
| @@ -1389,6 +1418,7 @@ The default comes from `process-coding-system-alist' and | |||
| 1389 | 1418 | ||
| 1390 | 1419 | ||
| 1391 | 1420 | ||
| 1421 | ;;;###autoload | ||
| 1392 | (defun sql-ingres () | 1422 | (defun sql-ingres () |
| 1393 | "Run sql by Ingres as an inferior process. | 1423 | "Run sql by Ingres as an inferior process. |
| 1394 | 1424 | ||
| @@ -1428,6 +1458,7 @@ The default comes from `process-coding-system-alist' and | |||
| 1428 | 1458 | ||
| 1429 | 1459 | ||
| 1430 | 1460 | ||
| 1461 | ;;;###autoload | ||
| 1431 | (defun sql-ms () | 1462 | (defun sql-ms () |
| 1432 | "Run isql by Microsoft as an inferior process. | 1463 | "Run isql by Microsoft as an inferior process. |
| 1433 | 1464 | ||