1 ;;; sql.el --- specialized comint.el for SQL interpreters
3 ;; Copyright (C) 1998, 1999 Free Software Foundation, Inc.
5 ;; Author: Alex Schroeder <a.schroeder@bsiag.ch>
6 ;; Maintainer: Alex Schroeder <a.schroeder@bsiag.ch>
8 ;; Keywords: comm languages processes
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; Please send bug reports and bug fixes to the mailing list at
30 ;; sql.el@gnu.org (or sql.el@bsiag.com). If you want to subscribe to
31 ;; the mailing list, send mail to sql.el-request@gnu.org with
32 ;; `subscribe sql.el FIRSTNAME LASTNAME' in the subject line.
34 ;; You can get the latest version of this file from my homepage
35 ;; <URL:http://www.geocities.com/TimesSquare/6120/emacs.html>.
37 ;; This file provides a sql-mode and a sql-interactive-mode. My goals
38 ;; were two simple modes providing syntactic hilighting. The
39 ;; interactive mode had to provide a command-line history; the other
40 ;; mode had to provide "send region/buffer to SQL interpreter"
41 ;; functions. "simple" in this context means easy to use, easy to
42 ;; maintain and little or no bells and whistles.
44 ;; If anybody feels like extending this sql mode, take a look at the
45 ;; above mentioned modes and write a sqlx-mode on top of this one. If
46 ;; this proves to be difficult, please suggest changes that will
47 ;; facilitate your plans.
49 ;; sql-interactive-mode is used to interact with a SQL interpreter
50 ;; process in a SQLi buffer (usually called `*SQL*'). The SQLi buffer
51 ;; is created by calling a SQL interpreter-specific entry function. Do
52 ;; *not* call sql-interactive-mode by itself.
54 ;; The list of currently supported interpreters and the corresponding
55 ;; entry function used to create the SQLi buffers is shown with
56 ;; `sql-help' (M-x sql-help).
58 ;; Since sql-interactive-mode is built on top of the general
59 ;; command-interpreter-in-a-buffer mode (comint mode), it shares a
60 ;; common base functionality, and a common set of bindings, with all
61 ;; modes derived from comint mode. This makes these modes easier to
64 ;; sql-mode can be used to enable syntactic hilighting for SQL
65 ;; statements in another buffer. SQL statements can then be sent to
66 ;; the SQL process in the SQLi buffer. sql-mode has already been
67 ;; used as a template to a simple PL/SQL mode.
69 ;; For documentation on the functionality provided by comint mode, and
70 ;; the hooks available for customising it, see the file `comint.el'.
72 ;; Hint for newbies: take a look at `dabbrev-expand' and `abbrev-mode'.
74 ;;; Requirements for Emacs 19.34:
76 ;; If you are using Emacs 19.34, you will have to get and install
77 ;; the file regexp-opt.el
78 ;; <URL:ftp://ftp.ifi.uio.no/pub/emacs/emacs-20.3/lisp/emacs-lisp/regexp-opt.el>
79 ;; and the custom package
80 ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>.
84 ;; Using sql-ms (isql by Microsoft): When commands with syntax errors
85 ;; or execution errors are executed, there is no server feedback.
86 ;; This happens in stored procedures for example. The server messages
87 ;; only appear after the process is exited. This makes things
88 ;; somewhat unreliable.
92 ;; Add better hilight support for other brands; there is a bias towards
93 ;; Oracle because that's what I use at work. Anybody else just send in
94 ;; your lists of reserved words, keywords and builtin functions! As
95 ;; long as I don't receive any feedback, everything is hilighted with
96 ;; ANSI keywords only. I received the list of ANSI keywords from a
97 ;; user; if you know of any changes, let me know.
99 ;; Add different hilighting levels.
101 ;;; Thanks to all the people who helped me out:
103 ;; Kai Blauberg <kai.blauberg@metla.fi>
104 ;; <ibalaban@dalet.com>
105 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il>
106 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
107 ;; nino <nino@inform.dk>
114 ;; Need the following to allow GNU Emacs 19 to compile the file.
115 (require 'regexp-opt
)
118 ;;; Allow customization
121 "Running a SQL interpreter from within Emacs buffers"
125 ;; These three variables will be used as defaults, if set.
127 (defcustom sql-user
""
132 (defcustom sql-password
""
135 Storing your password in a textfile such as ~/.emacs could be dangerous.
136 Customizing your password will store it in your ~/.emacs file."
140 (defcustom sql-database
""
145 (defcustom sql-server
""
146 "*Default server or host."
150 (defcustom sql-pop-to-buffer-after-send-region nil
151 "*If t, pop to the buffer SQL statements are sent to.
153 After a call to `sql-send-region' or `sql-send-buffer',
154 the window is split and the SQLi buffer is shown. If this
155 variable is not nil, that buffer's window will be selected
156 by calling `pop-to-buffer'. If this variable is nil, that
157 buffer is shown using `display-buffer'."
161 (defcustom sql-input-ring-file-name nil
162 "*If non-nil, name of the file to read/write input history.
164 You have to set this variable if you want the history of your commands
165 saved from one Emacs session to the next. If this variable is set,
166 exiting the SQL interpreter in an SQLi buffer will write the input
167 history to the specified file. Starting a new process in a SQLi buffer
168 will read the input history from the specified file.
170 You have to set this variable if you want the history of your commands
171 saved from one Emacs session to the next. If this variable is set,
172 exiting the SQL interpreter in an SQLi buffer will write the input
173 history to the specified file. Starting a new process in a SQLi buffer
174 will read the input history from the specified file.
176 This is used to locally set `comint-input-ring-file-name' when reading
177 or writing the input history."
178 :type
'(choice (const :tag
"none" nil
)
182 (defcustom sql-input-ring-separator
"\n--\n"
183 "*Separator between commands in the history file.
185 If set to \"\\n\", each line in the history file will be interpreted as
186 one command. Multi-line commands are split into several commands when
187 the input ring is initialized from a history file.
189 This variable used to locally set `comint-input-ring-separator' when
190 reading or writing the history file. `comint-input-ring-separator' is
191 not yet part of Emacs; if your Emacs does not have it, setting
192 `sql-input-ring-separator' will have no effect. In that case multiline
193 commands will be split into several commands when the input history is
194 read, as if you had set `sql-input-ring-separator' to \"\\n\".
196 The source code contains a link to a homepage that might have a patch
197 for comint.el to download."
203 (defcustom sql-interactive-mode-hook
'()
204 "*Hook for customising `sql-interactive-mode'."
208 (defcustom sql-mode-hook
'()
209 "*Hook for customising `sql-mode'."
213 (defcustom sql-set-sqli-hook
'()
214 "*Hook for reacting to changes of `sql-buffer'.
216 This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
221 ;; Customisation for Oracle
223 (defcustom sql-oracle-program
"sqlplus"
224 "*Command to start sqlplus by Oracle.
226 Starts `sql-interactive-mode' after doing some setup.
228 Under NT, \"sqlplus\" usually starts the sqlplus \"GUI\". In order to
229 start the sqlplus console, use \"plus33\" or something similar. You
230 will find the file in your Orant\\bin directory.
232 The program can also specify a TCP connection. See `make-comint'."
236 ;; Customisation for MySql
238 (defcustom sql-mysql-program
"mysql"
239 "*Command to start mysql by TcX.
241 Starts `sql-interactive-mode' after doing some setup.
243 The program can also specify a TCP connection. See `make-comint'."
247 ;; Customisation for Solid
249 (defcustom sql-solid-program
"solsql"
250 "*Command to start SOLID SQL Editor.
252 Starts `sql-interactive-mode' after doing some setup.
254 The program can also specify a TCP connection. See `make-comint'."
258 ;; Customisation for SyBase
260 (defcustom sql-sybase-program
"isql"
261 "*Command to start isql by SyBase.
263 Starts `sql-interactive-mode' after doing some setup.
265 The program can also specify a TCP connection. See `make-comint'."
269 ;; Customisation for Informix
271 (defcustom sql-informix-program
"dbaccess"
272 "*Command to start dbaccess by Informix.
274 Starts `sql-interactive-mode' after doing some setup.
276 The program can also specify a TCP connection. See `make-comint'."
280 ;; Customisation for Ingres
282 (defcustom sql-ingres-program
"sql"
283 "*Command to start sql by Ingres.
285 Starts `sql-interactive-mode' after doing some setup.
287 The program can also specify a TCP connection. See `make-comint'."
291 ;; Customisation for Microsoft
293 (defcustom sql-ms-program
"isql"
294 "*Command to start isql by Microsoft.
296 Starts `sql-interactive-mode' after doing some setup.
298 The program can also specify a TCP connection. See `make-comint'."
302 ;; Customisation for Postgres
304 (defcustom sql-postgres-program
"psql"
305 "Command to start psql by Postgres.
307 Starts `sql-interactive-mode' after doing some setup.
309 The program can also specify a TCP connection. See `make-comint'."
315 ;;; Variables which do not need customization
317 (defvar sql-user-history nil
318 "History of usernames used.")
320 (defvar sql-database-history nil
321 "History of databases used.")
323 (defvar sql-server-history nil
324 "History of servers used.")
326 ;; Passwords are not kept in a history.
328 (defvar sql-buffer nil
329 "Current SQLi buffer.
331 The global value of sql-buffer is the name of the latest SQLi buffer
332 created. Any SQL buffer created will make a local copy of this value.
333 See `sql-interactive-mode' for more on multiple sessions. If you want
334 to change the SQLi buffer a SQL mode sends its SQL strings to, change
335 the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
337 (defvar sql-prompt-regexp nil
338 "Prompt used to initialize `comint-prompt-regexp'.
340 You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.")
342 (defvar sql-prompt-length
0
343 "Prompt used to set `left-margin' in `sql-interactive-mode'.
345 You can change it on `sql-interactive-mode-hook'.")
347 (defvar sql-alternate-buffer-name nil
348 "Buffer-local string used to possibly rename the SQLi buffer.
350 Used by `sql-rename-buffer'.")
352 ;; Keymap for sql-interactive-mode, based on comint-mode-map.
354 (if (not (string-match "XEmacs\\|Lucid" emacs-version
))
355 (defvar sql-interactive-mode-map
356 (let ((map (nconc (make-sparse-keymap) comint-mode-map
)))
357 (define-key map
"\C-j" 'sql-accumulate-and-indent
)
358 (define-key map
"\C-c\C-w" 'sql-copy-column
)
360 "Mode map used for `sql-interactive-mode'.")
362 (defvar sql-interactive-mode-map nil
)
363 (if (not sql-interactive-mode-map
)
364 (let ((map (make-keymap)))
365 (set-keymap-parents map
(list comint-mode-map
))
366 (set-keymap-name map
'sql-interactive-mode-map
)
367 (define-key map
"\C-j" 'sql-accumulate-and-indent
)
368 (define-key map
"\C-c\C-w" 'sql-copy-column
)
369 (setq sql-interactive-mode-map map
))))
371 ;; Keymap for sql-mode.
374 (let ((map (make-sparse-keymap)))
375 (define-key map
"\C-c\C-c" 'sql-send-paragraph
)
376 (define-key map
"\C-c\C-r" 'sql-send-region
)
377 (define-key map
"\C-c\C-b" 'sql-send-buffer
)
378 (define-key map
"\t" 'indent-relative
)
380 "Mode map used for `sql-mode'.")
382 ;; easy menu for sql-mode.
385 sql-mode-menu sql-mode-map
386 "Menu for `sql-mode'."
388 ["Send Paragraph" sql-send-paragraph
(and (buffer-live-p sql-buffer
)
389 (get-buffer-process sql-buffer
))]
390 ["Send Region" sql-send-region
(and mark-active
391 (buffer-live-p sql-buffer
)
392 (get-buffer-process sql-buffer
))]
393 ["Send Buffer" sql-send-buffer
(and (buffer-live-p sql-buffer
)
394 (get-buffer-process sql-buffer
))]
395 ["Show SQLi buffer" sql-show-sqli-buffer t
]
396 ["Set SQLi buffer" sql-set-sqli-buffer t
]
397 ["Pop to SQLi buffer after send"
398 sql-toggle-pop-to-buffer-after-send-region
400 :selected sql-pop-to-buffer-after-send-region
]))
402 ;; easy menu for sql-interactive-mode.
405 sql-interactive-mode-menu sql-interactive-mode-map
406 "Menu for `sql-interactive-mode'."
408 ["Rename Buffer" sql-rename-buffer t
]))
410 ;; Abbreviations -- if you want more of them, define them in your
411 ;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too.
413 (defvar sql-mode-abbrev-table nil
414 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")
415 (if sql-mode-abbrev-table
418 (define-abbrev-table 'sql-mode-abbrev-table
())
419 (define-abbrev sql-mode-abbrev-table
"ins" "insert" nil
)
420 (define-abbrev sql-mode-abbrev-table
"upd" "update" nil
)
421 (define-abbrev sql-mode-abbrev-table
"del" "delete" nil
)
422 (define-abbrev sql-mode-abbrev-table
"sel" "select" nil
)))
426 (defvar sql-mode-syntax-table
427 (let ((table (make-syntax-table)))
428 ;; C-style comments /**/ (see elisp manual "Syntax Flags"))
429 (modify-syntax-entry ?
/ ". 14" table
)
430 (modify-syntax-entry ?
* ". 23" table
)
431 ;; double-dash starts comment
432 (if (string-match "XEmacs\\|Lucid" emacs-version
)
433 (modify-syntax-entry ?-
". 56" table
)
434 (modify-syntax-entry ?-
". 12b" table
))
435 ;; newline and formfeed end coments
436 (modify-syntax-entry ?
\n "> b" table
)
437 (modify-syntax-entry ?
\f "> b" table
)
438 ;; single quotes (') quotes delimit strings
439 (modify-syntax-entry ?
' "\"" table
)
441 "Syntax table used in `sql-mode' and `sql-interactive-mode'.")
445 (defvar sql-mode-ansi-font-lock-keywords nil
446 "ANSI SQL keywords used by font-lock.
448 This variable is used by `sql-mode' and `sql-interactive-mode'. The
449 regular expressions are created during compilation by calling the
450 function `regexp-opt'. Therefore, take a look at the source before
451 you define your own sql-mode-ansi-font-lock-keywords. You may want to
452 add functions and PL/SQL keywords.")
453 (if sql-mode-ansi-font-lock-keywords
455 (let ((ansi-keywords (eval-when-compile
458 "authorization" "avg" "begin" "close" "cobol" "commit"
459 "continue" "count" "declare" "double" "end" "escape"
460 "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"
461 "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli"
462 "precision" "primary" "procedure" "references" "rollback"
463 "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work") t
) "\\b")))
464 (ansi-reserved-words (eval-when-compile
467 "all" "and" "any" "as" "asc" "between" "by" "check" "create"
468 "current" "default" "delete" "desc" "distinct" "exists" "float" "for"
469 "from" "grant" "group" "having" "in" "insert" "into" "is"
470 "like" "not" "null" "of" "on" "option" "or" "order" "privileges"
471 "public" "select" "set" "table" "to" "union" "unique"
472 "update" "user" "values" "view" "where" "with") t
) "\\b")))
473 (ansi-types (eval-when-compile
476 ;; ANSI Keywords that look like types
477 "character" "cursor" "dec" "int" "real"
478 ;; ANSI Reserved Word that look like types
479 "char" "integer" "smallint" ) t
) "\\b"))))
480 (setq sql-mode-ansi-font-lock-keywords
481 (list (cons ansi-keywords
'font-lock-function-name-face
)
482 (cons ansi-reserved-words
'font-lock-keyword-face
)
483 (cons ansi-types
'font-lock-type-face
)))))
485 (defvar sql-mode-oracle-font-lock-keywords nil
486 "Oracle SQL keywords used by font-lock.
488 This variable is used by `sql-mode' and `sql-interactive-mode'. The
489 regular expressions are created during compilation by calling the
490 function `regexp-opt'. Therefore, take a look at the source before
491 you define your own sql-mode-oracle-font-lock-keywords. You may want
492 to add functions and PL/SQL keywords.")
493 (if sql-mode-oracle-font-lock-keywords
495 (let ((oracle-keywords (eval-when-compile
498 "admin" "after" "allocate" "analyze" "archive" "archivelog" "backup"
499 "become" "before" "block" "body" "cache" "cancel" "cascade" "change"
500 "checkpoint" "compile" "constraint" "constraints" "contents"
501 "controlfile" "cycle" "database" "datafile" "dba" "disable" "dismount"
502 "dump" "each" "enable" "events" "except" "exceptions" "execute"
503 "explain" "extent" "externally" "flush" "force" "freelist" "freelists"
504 "function" "groups" "including" "initrans" "instance" "layer" "link"
505 "lists" "logfile" "manage" "manual" "maxdatafiles" "maxinistances"
506 "maxlogfiles" "maxloghistory" "maxlogmembers" "maxtrans" "maxvalue"
507 "minextents" "minvalue" "mount" "new" "next" "noarchivelog" "nocache"
508 "nocycle" "nomaxvalue" "nominvalue" "none" "noorder" "noresetlogs"
509 "normal" "nosort" "off" "old" "only" "optimal" "own" "package"
510 "parallel" "pctincrease" "pctused" "plan" "private" "profile" "quota"
511 "read" "recover" "referencing" "resetlogs" "restricted" "reuse" "role"
512 "roles" "savepoint" "scn" "segment" "sequence" "shared" "snapshot"
513 "sort" "statement_id" "statistics" "stop" "storage" "switch" "system"
514 "tables" "tablespace" "temporary" "thread" "time" "tracing"
515 "transaction" "triggers" "truncate" "under" "unlimited" "until" "use"
516 "using" "when" "write") t
) "\\b")))
517 (oracle-reserved-words (eval-when-compile
520 "access" "add" "alter" "audit" "cluster" "column" "comment" "compress"
521 "connect" "drop" "else" "exclusive" "file" "grant"
522 "identified" "immediate" "increment" "index" "initial" "intersect"
523 "level" "lock" "long" "maxextents" "minus" "mode" "modify" "noaudit"
524 "nocompress" "nowait" "number" "offline" "online" "pctfree" "prior"
525 "raw" "rename" "resource" "revoke" "row" "rowlabel" "rownum"
526 "rows" "session" "share" "size" "start" "successful" "synonym" "sysdate"
527 "then" "trigger" "uid" "validate" "whenever") t
) "\\b")))
528 (oracle-types (eval-when-compile
531 ;; Oracle Keywords that look like types
532 ;; Oracle Reserved Words that look like types
533 "date" "decimal" "rowid" "varchar" "varchar2") t
) "\\b")))
534 (oracle-builtin-functions (eval-when-compile
537 ;; Misc Oracle builtin functions
538 "abs" "add_months" "ascii" "avg" "ceil" "chartorowid" "chr" "concat"
539 "convert" "cos" "cosh" "count" "currval" "decode" "dump" "exp" "floor"
540 "glb" "greatest" "greatest_lb" "hextoraw" "initcap" "instr" "instrb"
541 "last_day" "least" "least_ub" "length" "lengthb" "ln" "log" "lower"
542 "lpad" "ltrim" "lub" "max" "min" "mod" "months_between" "new_time"
543 "next_day" "nextval" "nls_initcap" "nls_lower" "nls_upper" "nlssort"
544 "nvl" "power" "rawtohex" "replace" "round" "rowidtochar" "rpad"
545 "rtrim" "sign" "sin" "sinh" "soundex" "sqlcode" "sqlerrm" "sqrt"
546 "stddev" "sum" "substr" "substrb" "tan" "tanh" "to_char"
547 "to_date" "to_label" "to_multi_byte" "to_number" "to_single_byte"
548 "translate" "trunc" "uid" "upper" "userenv" "variance" "vsize") t
) "\\b"))))
549 (setq sql-mode-oracle-font-lock-keywords
550 (append sql-mode-ansi-font-lock-keywords
551 (list (cons oracle-keywords
'font-lock-function-name-face
)
552 (cons oracle-reserved-words
'font-lock-keyword-face
)
553 ;; XEmacs doesn't have font-lock-builtin-face
554 (if (string-match "XEmacs\\|Lucid" emacs-version
)
555 (cons oracle-builtin-functions
'font-lock-preprocessor-face
)
556 ;; GNU Emacs 19 doesn't have it either
557 (if (string-match "GNU Emacs 19" emacs-version
)
558 (cons oracle-builtin-functions
'font-lock-function-name-face
)
560 (cons oracle-builtin-functions
'font-lock-builtin-face
)))
561 (cons oracle-types
'font-lock-type-face
))))))
563 (defvar sql-mode-postgres-font-lock-keywords nil
564 "Postgres SQL keywords used by font-lock.
566 This variable is used by `sql-mode' and `sql-interactive-mode'. The
567 regular expressions are created during compilation by calling the
568 function `regexp-opt'. Therefore, take a look at the source before
569 you define your own sql-mode-postgres-font-lock-keywords.")
571 (if sql-mode-postgres-font-lock-keywords
573 (let ((postgres-reserved-words (eval-when-compile
578 (postgres-types (eval-when-compile
581 "bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date"
582 "float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path"
583 "point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar"
585 (postgres-builtin-functions (eval-when-compile
588 ;; Misc Postgres builtin functions
589 "abstime" "age" "area" "box" "center" "date_part" "date_trunc"
590 "datetime" "dexp" "diameter" "dpow" "float" "float4" "height"
591 "initcap" "integer" "isclosed" "isfinite" "isoldpath" "isopen"
592 "length" "lower" "lpad" "ltrim" "pclose" "point" "points" "popen"
593 "position" "radius" "reltime" "revertpoly" "rpad" "rtrim" "substr"
594 "substring" "text" "timespan" "translate" "trim" "upgradepath"
595 "upgradepoly" "upper" "varchar" "width"
597 (setq sql-mode-postgres-font-lock-keywords
598 (append sql-mode-ansi-font-lock-keywords
599 (list (cons postgres-reserved-words
'font-lock-keyword-face
)
600 ;; XEmacs doesn't have 'font-lock-builtin-face
601 (if (string-match "XEmacs\\|Lucid" emacs-version
)
602 (cons postgres-builtin-functions
'font-lock-preprocessor-face
)
604 (cons postgres-builtin-functions
'font-lock-builtin-face
))
605 (cons postgres-types
'font-lock-type-face
))))))
608 (defvar sql-mode-font-lock-keywords sql-mode-ansi-font-lock-keywords
609 "SQL keywords used by font-lock.
611 This variable defaults to `sql-mode-ansi-font-lock-keywords'. This is
612 used for the default `font-lock-defaults' value in `sql-mode'. This
613 can be changed by some entry functions to provide more hilighting.")
619 (defun sql-accumulate-and-indent ()
620 "Continue SQL statement on the next line."
622 (if (fboundp 'comint-accumulate
) (comint-accumulate))
623 (indent-according-to-mode))
627 "Shows short help for the SQL modes.
629 Use an entry function to open an interactive SQL buffer. This buffer is
630 usually named `*SQL*'. The name of the major mode is SQLi.
632 Use the following commands to start a specific SQL interpreter:
634 PostGres: \\[sql-postgres]
636 Other non-free SQL implementations are also supported:
640 Oracle: \\[sql-oracle]
641 Informix: \\[sql-informix]
642 Sybase: \\[sql-sybase]
643 Ingres: \\[sql-ingres]
644 Microsoft: \\[sql-ms]
646 But we urge you to choose a free implementation instead of these.
648 Once you have the SQLi buffer, you can enter SQL statements in the
649 buffer. The output generated is appended to the buffer and a new prompt
650 is generated. See the In/Out menu in the SQLi buffer for some functions
651 that help you navigate through the buffer, the input history, etc.
653 Put a line with a call to autoload into your `~/.emacs' file for each
654 entry function you want to use regularly:
656 \(autoload 'sql-postgres \"sql\" \"Interactive SQL mode.\" t)
658 If you have a really complex SQL statement or if you are writing a
659 procedure, you can do this in a separate buffer. Put the new buffer in
660 `sql-mode' by calling \\[sql-mode]. The name of this buffer can be
661 anything. The name of the major mode is SQL.
663 In this SQL buffer (SQL mode), you can send the region or the entire
664 buffer to the interactive SQL buffer (SQLi mode). The results are
665 appended to the SQLi buffer without disturbing your SQL buffer."
667 (describe-function 'sql-help
))
669 (defun sql-read-passwd (prompt &optional default
)
670 "Read a password using PROMPT.
671 Optional DEFAULT is password to start with. This function calls
672 `read-passwd' if it is available. If not, function
673 `ange-ftp-read-passwd' is called. This should always be available,
674 even in old versions of Emacs."
675 (if (fboundp 'read-passwd
)
676 (read-passwd prompt nil default
)
677 (unless (fboundp 'ange-ftp-read-passwd
)
678 (autoload 'ange-ftp-read-passwd
"ange-ftp"))
679 (ange-ftp-read-passwd prompt default
)))
681 (defun sql-get-login (&rest what
)
682 "Get username, password and database from the user.
684 The variables `sql-user', `sql-password', `sql-server', and
685 `sql-database' can be customised. They are used as the default values.
686 Usernames, servers and databases are stored in `sql-user-history',
687 `sql-server-history' and `database-history'. Passwords are not stored
690 Parameter WHAT is a list of the arguments passed to this function.
691 The function asks for the username if WHAT contains symbol `user', for
692 the password if it contains symbol `password', for the server if it
693 contains symbol `server', and for the database if it contains symbol
696 In order to ask the user for username, password and database, call the
697 function like this: (sql-get-login 'user 'password 'database)."
699 (if (memq 'user what
)
701 (read-from-minibuffer "User: " sql-user nil nil
703 (if (memq 'password what
)
705 (sql-read-passwd "Password: " sql-password
)))
706 (if (memq 'server what
)
708 (read-from-minibuffer "Server: " sql-server nil nil
709 sql-server-history
)))
710 (if (memq 'database what
)
712 (read-from-minibuffer "Database: " sql-database nil nil
713 sql-database-history
))))
714 (defun sql-set-sqli-buffer ()
715 "Set the SQLi buffer SQL strings are sent to.
717 Call this function in a SQL buffer in order to set the SQLi buffer SQL
718 strings are sent to. Calling this function sets `sql-buffer' and runs
721 If you call it from a SQL buffer, this sets the local copy of
724 If you call it from anywhere else, it sets the global copy of
727 (let ((new-buffer (get-buffer (read-buffer "New SQLi buffer: " nil t
))))
730 (setq sql-buffer new-buffer
)
731 (run-hooks 'sql-set-sqli-hook
)))))
733 (defun sql-show-sqli-buffer ()
734 "Show the name of current SQLi buffer.
736 This is the buffer SQL strings are sent to. It is stored in the
737 variable `sql-buffer'. See `sql-help' on how to create such a buffer."
739 (if (null (buffer-live-p sql-buffer
))
740 (message "%s has no SQLi buffer set." (buffer-name (current-buffer)))
741 (if (null (get-buffer-process sql-buffer
))
742 (message "Buffer %s has no process." (buffer-name sql-buffer
))
743 (message "Current SQLi buffer is %s." (buffer-name sql-buffer
)))))
745 (defun sql-make-alternate-buffer-name ()
746 "Return a string that can be used to rename a SQLi buffer.
748 This is used to set `sql-alternate-buffer-name' within
749 `sql-interactive-mode'."
750 (concat (if (string= "" sql-user
)
751 (if (string= "" user-login-name
)
753 (concat user-login-name
"/"))
754 (concat sql-user
"/"))
755 (if (string= "" sql-database
)
756 (if (string= "" sql-server
)
761 (defun sql-rename-buffer ()
762 "Renames a SQLi buffer."
764 (rename-buffer (format "*SQL: %s*" sql-alternate-buffer-name
) t
))
766 (defun sql-copy-column ()
767 "Copy current column to the end of buffer.
768 Inserts SELECT or commas if appropriate."
772 (setq column
(buffer-substring
773 (progn (forward-char 1) (backward-sexp 1) (point))
774 (progn (forward-sexp 1) (point))))
775 (goto-char (point-max))
777 ;; if empty command line, insert SELECT
778 ((save-excursion (beginning-of-line)
779 (looking-at (concat comint-prompt-regexp
"$")))
781 ;; else if appending to SELECT or ORDER BY, insert a comma
783 (re-search-backward "\\b\\(select\\|order by\\) .+"
784 (save-excursion (beginning-of-line) (point)) t
))
786 ;; else insert a space
788 (if (eq (preceding-char) ?
)
791 ;; in any case, insert the column
793 (message "%s" column
))))
797 ;;; Sending the region to the SQLi buffer.
799 (defun sql-send-region (start end
)
800 "Send a region to the SQL process."
802 (if (buffer-live-p sql-buffer
)
804 (comint-send-region sql-buffer start end
)
805 (if (string-match "\n$" (buffer-substring start end
))
807 (comint-send-string sql-buffer
"\n"))
808 (message "Sent string to buffer %s." (buffer-name sql-buffer
))
809 (if sql-pop-to-buffer-after-send-region
810 (pop-to-buffer sql-buffer
)
811 (display-buffer sql-buffer
)))
812 (message "No SQL process started.")))
814 (defun sql-send-paragraph ()
815 "Send the current paragraph to the SQL process."
817 (let ((start (save-excursion
823 (sql-send-region start end
)))
825 (defun sql-send-buffer ()
826 "Send the buffer contents to the SQL process."
828 (sql-send-region (point-min) (point-max)))
830 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value
)
831 "Toggle `sql-pop-to-buffer-after-send-region'.
833 If given the optional parameter VALUE, sets
834 sql-toggle-pop-to-buffer-after-send-region to VALUE."
837 (setq sql-pop-to-buffer-after-send-region value
)
838 (setq sql-pop-to-buffer-after-send-region
839 (null sql-pop-to-buffer-after-send-region
))))
843 ;;; SQL mode -- uses SQL interactive mode
847 "Major mode to edit SQL.
849 You can send SQL statements to the SQLi buffer using
850 \\[sql-send-region]. Such a buffer must exist before you can do this.
851 See `sql-help' on how to create SQLi buffers.
854 Customization: Entry to this mode runs the `sql-mode-hook'.
856 When you put a buffer in SQL mode, the buffer stores the last SQLi
857 buffer created as its destination in the variable `sql-buffer'. This
858 will be the buffer \\[sql-send-region] sends the region to. If this
859 SQLi buffer is killed, \\[sql-send-region] is no longer able to
860 determine where the strings should be sent to. You can set the
861 value of `sql-buffer' using \\[sql-set-sqli-buffer].
863 For information on how to create multiple SQLi buffers, see
864 `sql-interactive-mode'."
866 (kill-all-local-variables)
867 (setq major-mode
'sql-mode
)
868 (setq mode-name
"SQL")
869 (use-local-map sql-mode-map
)
870 (set-syntax-table sql-mode-syntax-table
)
871 (make-local-variable 'font-lock-defaults
)
872 (setq font-lock-defaults
'(sql-mode-font-lock-keywords
873 nil t
((95 .
"w") (46 .
"w"))))
874 (make-local-variable 'comment-start
)
875 (setq comment-start
"--")
876 ;; Make each buffer in sql-mode remeber the "current" SQLi buffer.
877 (make-local-variable 'sql-buffer
)
878 ;; Make `sql-send-paragraph' work on paragraphs that contain indented
880 (make-local-variable 'paragraph-separate
)
881 (make-local-variable 'paragraph-start
)
882 (setq paragraph-separate
"[\f]*$"
883 paragraph-start
"[\n\f]")
884 (setq local-abbrev-table sql-mode-abbrev-table
)
885 (setq abbrev-all-caps
1)
886 (run-hooks 'sql-mode-hook
))
890 ;;; SQL interactive mode
892 (put 'sql-interactive-mode
'mode-class
'special
)
894 (defun sql-interactive-mode ()
895 "Major mode to use a SQL interpreter interactively.
897 Do not call this function by yourself. The environment must be
898 initialized by an entry function specific for the SQL interpreter. See
899 `sql-help' for a list of available entry functions.
901 \\[comint-send-input] after the end of the process' output sends the
902 text from the end of process to the end of the current line.
903 \\[comint-send-input] before end of process output copies the current
904 line minus the prompt to the end of the buffer and sends it.
905 \\[comint-copy-old-input] just copies the current line.
906 Use \\[sql-accumulate-and-indent] to enter multi-line statements.
908 If you want to make multiple SQL buffers, rename the `*SQL*' buffer
909 using \\[rename-buffer] or \\[rename-uniquely] and start a new process.
910 See `sql-help' for a list of available entry functions. The last buffer
911 created by such an entry function is the current SQLi buffer. SQL
912 buffers will send strings to the SQLi buffer current at the time of
913 their creation. See `sql-mode' for details.
915 Sample session using two connections:
917 1. Create first SQLi buffer by calling an entry function.
918 2. Rename buffer \"*SQL*\" to \"*Connection 1*\".
919 3. Create a SQL buffer \"test1.sql\".
920 4. Create second SQLi buffer by calling an entry function.
921 5. Rename buffer \"*SQL*\" to \"*Connection 2*\".
922 6. Create a SQL buffer \"test2.sql\".
924 Now \\[sql-send-region] in buffer \"test1.sql\" will send the region to
925 buffer \"*Connection 1*\", \\[sql-send-region] in buffer \"test2.sql\"
926 will send the region to buffer \"*Connection 2*\".
928 If you accidentally suspend your process, use \\[comint-continue-subjob]
929 to continue it. On some operating systems, this will not work because
930 the signals are not supported.
932 \\{sql-interactive-mode-map}
933 Customization: Entry to this mode runs the hooks on `comint-mode-hook'
934 and `sql-interactive-mode-hook' (in that order). Before each input, the
935 hooks on `comint-input-filter-functions' are run. After each SQL
936 interpreter output, the hooks on `comint-output-filter-functions' are
939 Variable `sql-input-ring-file-name' controls the initialisation of the
940 input ring history. `comint-input-ring-file-name' is temporarily bound
941 to `sql-input-ring-file-name' when reading the input history.
943 Variables `comint-output-filter-functions', a hook, and
944 `comint-scroll-to-bottom-on-input' and
945 `comint-scroll-to-bottom-on-output' control whether input and output
946 cause the window to scroll to the end of the buffer.
948 If you want to make SQL buffers limited in length, add the function
949 `comint-truncate-buffer' to `comint-output-filter-functions'.
951 Here is an example for your .emacs file. It keeps the SQLi buffer a
954 \(add-hook 'sql-interactive-mode-hook
955 \(function (lambda ()
956 \(setq comint-output-filter-functions 'comint-truncate-buffer))))
958 Here is another example. It will always put point back to the statement
959 you entered, right above the output it created.
961 \(setq comint-output-filter-functions
962 \(function (lambda (STR) (comint-show-output))))"
964 (setq comint-prompt-regexp sql-prompt-regexp
)
965 (setq left-margin sql-prompt-length
)
966 (setq major-mode
'sql-interactive-mode
)
967 (setq mode-name
"SQLi")
968 (use-local-map sql-interactive-mode-map
)
969 (set-syntax-table sql-mode-syntax-table
)
970 (make-local-variable 'font-lock-defaults
)
971 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
972 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the
973 ;; column will have just one quote. Therefore syntactic hilighting
974 ;; is disabled for interactive buffers.
975 (setq font-lock-defaults
'(sql-mode-font-lock-keywords
976 t t
((95 .
"w") (46 .
"w"))))
977 ;; Enable commenting and uncommenting of the region.
978 (make-local-variable 'comment-start
)
979 (setq comment-start
"--")
980 ;; Abbreviation table init and case-insensitive. It is not activatet
982 (setq local-abbrev-table sql-mode-abbrev-table
)
983 (setq abbrev-all-caps
1)
984 ;; Exiting the process will call sql-stop.
985 (set-process-sentinel (get-buffer-process sql-buffer
) 'sql-stop
)
986 ;; Make input-ring stuff buffer local so that people who want a
987 ;; different history file for each buffer/process/client/whatever can
988 ;; change separator and file-name on the sql-interactive-mode-hook.
989 (make-local-variable 'sql-input-ring-separator
)
990 (make-local-variable 'sql-input-ring-file-name
)
991 ;; Create a usefull name for renaming this buffer later.
992 (make-local-variable 'sql-alternate-buffer-name
)
993 (setq sql-alternate-buffer-name
(sql-make-alternate-buffer-name))
995 (run-hooks 'sql-interactive-mode-hook
)
996 ;; Calling the hook before calling comint-read-input-ring allows users
997 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook.
998 ;; While reading the history, file-name and history are rebound...
999 (let ((comint-input-ring-file-name sql-input-ring-file-name
)
1000 (comint-input-ring-separator sql-input-ring-separator
))
1001 (comint-read-input-ring t
)))
1003 (defun sql-stop (process event
)
1004 "Called when the SQL process is stopped.
1006 Writes the input history to a history file using
1007 `comint-write-input-ring' and inserts a short message in the SQL buffer.
1008 `comint-comint-input-ring-file-name' is temporarily bound to
1009 `sql-input-ring-file-name'.
1011 This function is a sentinel watching the SQL interpreter process.
1012 Sentinels will always get the two parameters PROCESS and EVENT."
1014 ;; While reading the history, file-name and history are rebound...
1015 (let ((comint-input-ring-file-name sql-input-ring-file-name
)
1016 (comint-input-ring-separator sql-input-ring-separator
))
1017 (comint-write-input-ring))
1018 (if (buffer-live-p sql-buffer
)
1019 (insert (format "\nProcess %s %s\n" process event
))))
1023 ;;; Entry functions for different SQL interpreters.
1025 (defun sql-oracle ()
1026 "Run sqlplus by Oracle as an inferior process.
1028 If buffer `*SQL*' exists but no process is running, make a new process.
1029 If buffer exists and a process is running, just switch to buffer
1032 Interpreter used comes from variable `sql-oracle-program'. Login uses
1033 the variables `sql-user', `sql-password', and `sql-database' as
1036 The buffer is put in sql-interactive-mode, giving commands for sending
1037 input. See `sql-interactive-mode'.
1039 To specify a coding system for converting non-ASCII characters
1040 in the input and output to the process, use \\[universal-coding-system-argument]
1041 before \\[sql-oracle]. You can also specify this with \\[set-buffer-process-coding-system]
1042 in the SQL buffer, after you start the process.
1043 The default comes from `process-coding-system-alist' and
1044 `default-process-coding-system'.
1046 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1048 (if (comint-check-proc "*SQL*")
1049 (pop-to-buffer "*SQL*")
1050 (sql-get-login 'user
'password
'database
)
1051 (message "Login...")
1052 ;; Produce user/password@database construct. Password without user
1053 ;; is meaningless; database without user/password is meaningless,
1054 ;; because "@param" will ask sqlplus to interpret the script
1056 (let ((parameter nil
))
1057 (if (not (string= "" sql-user
))
1058 (if (not (string= "" sql-password
))
1059 (setq parameter
(concat sql-user
"/" sql-password
))
1060 (setq parameter sql-user
)))
1061 (if (and parameter
(not (string= "" sql-database
)))
1062 (setq parameter
(concat parameter
"@" sql-database
)))
1064 (set-buffer (make-comint "SQL" sql-oracle-program nil parameter
))
1065 (set-buffer (make-comint "SQL" sql-oracle-program nil
))))
1066 (setq sql-prompt-regexp
"^SQL> ")
1067 (setq sql-prompt-length
5)
1068 (setq sql-buffer
(current-buffer))
1069 ;; set sql-mode-font-lock-keywords to something different before
1070 ;; calling sql-interactive-mode.
1071 (setq sql-mode-font-lock-keywords sql-mode-oracle-font-lock-keywords
)
1072 (sql-interactive-mode)
1073 (message "Login...done")
1074 (pop-to-buffer sql-buffer
)))
1078 (defun sql-sybase ()
1079 "Run isql by SyBase as an inferior process.
1081 If buffer `*SQL*' exists but no process is running, make a new process.
1082 If buffer exists and a process is running, just switch to buffer
1085 Interpreter used comes from variable `sql-sybase-program'. Login uses
1086 the variables `sql-user', `sql-password', and `sql-database' as
1089 The buffer is put in sql-interactive-mode, giving commands for sending
1090 input. See `sql-interactive-mode'.
1092 To specify a coding system for converting non-ASCII characters
1093 in the input and output to the process, use \\[universal-coding-system-argument]
1094 before \\[sql-sybase]. You can also specify this with \\[set-buffer-process-coding-system]
1095 in the SQL buffer, after you start the process.
1096 The default comes from `process-coding-system-alist' and
1097 `default-process-coding-system'.
1099 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1101 (if (comint-check-proc "*SQL*")
1102 (pop-to-buffer "*SQL*")
1103 (sql-get-login 'user
'password
'database
)
1104 (message "Login...")
1105 ;; Put all parameters to the program (if defined) in a list and call
1107 (let ((params '("-w" "2048" "-n")))
1108 ;; I had a zillion versions of this using nconc and mapcar,
1109 ;; mixtures of eval, list and quotes -- you have been warned.
1110 (if (not (string= "" sql-database
))
1111 (setq params
(append (list "-S" sql-database
) params
)))
1112 (if (not (string= "" sql-password
))
1113 (setq params
(append (list "-P" sql-password
) params
)))
1114 (if (not (string= "" sql-user
))
1115 (setq params
(append (list "-U" sql-user
) params
)))
1116 (set-buffer (apply 'make-comint
"SQL" sql-sybase-program
1118 (setq sql-prompt-regexp
"^SQL> ")
1119 (setq sql-prompt-length
5)
1120 (setq sql-buffer
(current-buffer))
1121 (sql-interactive-mode)
1122 (message "Login...done")
1123 (pop-to-buffer sql-buffer
)))
1127 (defun sql-informix ()
1128 "Run dbaccess by Informix as an inferior process.
1130 If buffer `*SQL*' exists but no process is running, make a new process.
1131 If buffer exists and a process is running, just switch to buffer
1134 Interpreter used comes from variable `sql-informix-program'. Login uses
1135 the variable `sql-database' as default, if set.
1137 The buffer is put in sql-interactive-mode, giving commands for sending
1138 input. See `sql-interactive-mode'.
1140 To specify a coding system for converting non-ASCII characters
1141 in the input and output to the process, use \\[universal-coding-system-argument]
1142 before \\[sql-informix]. You can also specify this with \\[set-buffer-process-coding-system]
1143 in the SQL buffer, after you start the process.
1144 The default comes from `process-coding-system-alist' and
1145 `default-process-coding-system'.
1147 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1149 (if (comint-check-proc "*SQL*")
1150 (pop-to-buffer "*SQL*")
1151 (sql-get-login 'database
)
1152 (message "Login...")
1153 ;; username and password are ignored.
1154 (if (string= "" sql-database
)
1155 (set-buffer (make-comint "SQL" sql-informix-program nil
))
1156 (set-buffer (make-comint "SQL" sql-informix-program nil sql-database
)))
1157 (setq sql-prompt-regexp
"^SQL> ")
1158 (setq sql-prompt-length
5)
1159 (setq sql-buffer
(current-buffer))
1160 (sql-interactive-mode)
1161 (message "Login...done")
1162 (pop-to-buffer sql-buffer
)))
1167 "Run mysql by TcX as an inferior process.
1169 Note that the widespread idea that mysql is free software is inaccurate;
1170 its license is too restrictive. We urge you to use PostGres instead.
1172 If buffer `*SQL*' exists but no process is running, make a new process.
1173 If buffer exists and a process is running, just switch to buffer
1176 Interpreter used comes from variable `sql-mysql-program'. Login uses
1177 the variables `sql-user', `sql-password', `sql-database', and
1178 `sql-server' as defaults, if set.
1180 The buffer is put in sql-interactive-mode, giving commands for sending
1181 input. See `sql-interactive-mode'.
1183 To specify a coding system for converting non-ASCII characters
1184 in the input and output to the process, use \\[universal-coding-system-argument]
1185 before \\[sql-mysql]. You can also specify this with \\[set-buffer-process-coding-system]
1186 in the SQL buffer, after you start the process.
1187 The default comes from `process-coding-system-alist' and
1188 `default-process-coding-system'.
1190 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1192 (if (comint-check-proc "*SQL*")
1193 (pop-to-buffer "*SQL*")
1194 (sql-get-login 'user
'password
'database
'server
)
1195 (message "Login...")
1196 ;; Put all parameters to the program (if defined) in a list and call
1199 (if (not (string= "" sql-database
))
1200 (setq params
(append (list sql-database
) params
)))
1201 (if (not (string= "" sql-server
))
1202 (setq params
(append (list (concat "--host=" sql-server
)) params
)))
1203 (if (not (string= "" sql-password
))
1204 (setq params
(append (list (concat "--password=" sql-password
)) params
)))
1205 (if (not (string= "" sql-user
))
1206 (setq params
(append (list (concat "--user=" sql-user
)) params
)))
1207 (set-buffer (apply 'make-comint
"SQL" sql-mysql-program
1209 (setq sql-prompt-regexp
"^mysql>")
1210 (setq sql-prompt-length
6)
1211 (setq sql-buffer
(current-buffer))
1212 (sql-interactive-mode)
1213 (message "Login...done")
1214 (pop-to-buffer sql-buffer
)))
1219 "Run solsql by Solid as an inferior process.
1221 If buffer `*SQL*' exists but no process is running, make a new process.
1222 If buffer exists and a process is running, just switch to buffer
1225 Interpreter used comes from variable `sql-solid-program'. Login uses
1226 the variables `sql-user', `sql-password', and `sql-server' as
1229 The buffer is put in sql-interactive-mode, giving commands for sending
1230 input. See `sql-interactive-mode'.
1232 To specify a coding system for converting non-ASCII characters
1233 in the input and output to the process, use \\[universal-coding-system-argument]
1234 before \\[sql-solid]. You can also specify this with \\[set-buffer-process-coding-system]
1235 in the SQL buffer, after you start the process.
1236 The default comes from `process-coding-system-alist' and
1237 `default-process-coding-system'.
1239 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1241 (if (comint-check-proc "*SQL*")
1242 (pop-to-buffer "*SQL*")
1243 (sql-get-login 'user
'password
'server
)
1244 (message "Login...")
1245 ;; Put all parameters to the program (if defined) in a list and call
1248 ;; It only makes sense if both username and password are there.
1249 (if (not (or (string= "" sql-user
)
1250 (string= "" sql-password
)))
1251 (setq params
(append (list sql-user sql-password
) params
)))
1252 (if (not (string= "" sql-server
))
1253 (setq params
(append (list sql-server
) params
)))
1254 (set-buffer (apply 'make-comint
"SQL" sql-solid-program
1256 (setq sql-prompt-regexp
"^")
1257 (setq sql-prompt-length
0)
1258 (setq sql-buffer
(current-buffer))
1259 (sql-interactive-mode)
1260 (message "Login...done")
1261 (pop-to-buffer sql-buffer
)))
1265 (defun sql-ingres ()
1266 "Run sql by Ingres as an inferior process.
1268 If buffer `*SQL*' exists but no process is running, make a new process.
1269 If buffer exists and a process is running, just switch to buffer
1272 Interpreter used comes from variable `sql-ingres-program'. Login uses
1273 the variable `sql-database' as default, if set.
1275 The buffer is put in sql-interactive-mode, giving commands for sending
1276 input. See `sql-interactive-mode'.
1278 To specify a coding system for converting non-ASCII characters
1279 in the input and output to the process, use \\[universal-coding-system-argument]
1280 before \\[sql-ingres]. You can also specify this with \\[set-buffer-process-coding-system]
1281 in the SQL buffer, after you start the process.
1282 The default comes from `process-coding-system-alist' and
1283 `default-process-coding-system'.
1285 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1287 (if (comint-check-proc "*SQL*")
1288 (pop-to-buffer "*SQL*")
1289 (sql-get-login 'database
)
1290 (message "Login...")
1291 ;; username and password are ignored.
1292 (if (string= "" sql-database
)
1293 (set-buffer (make-comint "SQL" sql-ingres-program nil
))
1294 (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database
)))
1295 (setq sql-prompt-regexp
"^\* ")
1296 (setq sql-prompt-length
2)
1297 (setq sql-buffer
(current-buffer))
1298 (sql-interactive-mode)
1299 (message "Login...done")
1300 (pop-to-buffer sql-buffer
)))
1305 "Run isql by Microsoft as an inferior process.
1307 If buffer `*SQL*' exists but no process is running, make a new process.
1308 If buffer exists and a process is running, just switch to buffer
1311 Interpreter used comes from variable `sql-ms-program'. Login uses the
1312 variables `sql-user', `sql-password', `sql-database', and `sql-server'
1313 as defaults, if set.
1315 The buffer is put in sql-interactive-mode, giving commands for sending
1316 input. See `sql-interactive-mode'.
1318 To specify a coding system for converting non-ASCII characters
1319 in the input and output to the process, use \\[universal-coding-system-argument]
1320 before \\[sql-ms]. You can also specify this with \\[set-buffer-process-coding-system]
1321 in the SQL buffer, after you start the process.
1322 The default comes from `process-coding-system-alist' and
1323 `default-process-coding-system'.
1325 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1327 (if (comint-check-proc "*SQL*")
1328 (pop-to-buffer "*SQL*")
1329 (sql-get-login 'user
'password
'database
'server
)
1330 (message "Login...")
1331 ;; Put all parameters to the program (if defined) in a list and call
1333 (let ((params '("-w 300")))
1334 (if (not (string= "" sql-server
))
1335 (setq params
(append (list "-S" sql-server
) params
)))
1336 (if (not (string= "" sql-database
))
1337 (setq params
(append (list "-d" sql-database
) params
)))
1338 (if (not (string= "" sql-user
))
1339 (setq params
(append (list "-U" sql-user
) params
)))
1340 (if (not (string= "" sql-password
))
1341 (setq params
(append (list "-P" sql-password
) params
))
1342 ;; If -P is passed to ISQL as the last argument without a password,
1343 ;; it's considered null.
1344 (setq params
(append params
(list "-P"))))
1345 (set-buffer (apply 'make-comint
"SQL" sql-ms-program
1347 (setq sql-prompt-regexp
"^[0-9]*>")
1348 (setq sql-prompt-length
5)
1349 (setq sql-buffer
(current-buffer))
1350 (sql-interactive-mode)
1351 (message "Login...done")
1352 (pop-to-buffer sql-buffer
)))
1358 (defun sql-postgres ()
1359 "Run psql by Postgres as an inferior process.
1361 If buffer `*SQL*' exists but no process is running, make a new process.
1362 If buffer exists and a process is running, just switch to buffer
1365 Interpreter used comes from variable `sql-postgres-program'. Login uses
1366 the variables `sql-database' and `sql-server' as default, if set.
1368 The buffer is put in sql-interactive-mode, giving commands for sending
1369 input. See `sql-interactive-mode'.
1371 To specify a coding system for converting non-ASCII characters
1372 in the input and output to the process, use \\[universal-coding-system-argument]
1373 before \\[sql-postgres]. You can also specify this with \\[set-buffer-process-coding-system]
1374 in the SQL buffer, after you start the process.
1375 The default comes from `process-coding-system-alist' and
1376 `default-process-coding-system'. If your output lines end with ^M,
1377 your might try undecided-dos as a coding system. If this doesn't help,
1378 Try to set `comint-output-filter-functions' like this:
1380 \(setq comint-output-filter-functions (append comint-output-filter-functions
1381 '(comint-strip-ctrl-m)))
1383 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1385 (if (comint-check-proc "*SQL*")
1386 (pop-to-buffer "*SQL*")
1387 (sql-get-login 'database
'server
)
1388 (message "Login...")
1389 ;; username and password are ignored.
1391 (if (not (string= "" sql-database
))
1392 (setq params
(append (list sql-database
) params
)))
1393 (if (not (string= "" sql-server
))
1394 (setq params
(append (list "-h" sql-server
) params
)))
1395 (set-buffer (apply 'make-comint
"SQL" sql-postgres-program
1397 (setq sql-prompt-regexp
"^.*> *")
1398 (setq sql-prompt-length
5)
1399 ;; This is a lousy hack to prevent psql from truncating it's output
1400 ;; and giving stupid warnings. If s.o. knows a way to prevent psql
1401 ;; from acting this way, then I would be very thankful to
1402 ;; incorporate this (Gregor Zych <zych@pool.informatik.rwth-aachen.de>)
1403 (comint-send-string "*SQL*" "\\o \| cat\n")
1404 (setq sql-mode-font-lock-keywords sql-mode-postgres-font-lock-keywords
)
1405 (setq sql-buffer
(current-buffer))
1406 (sql-interactive-mode)
1407 (message "Login...done")
1408 (pop-to-buffer sql-buffer
)))
1412 ;;; sql.el ends here