]> code.delx.au - gnu-emacs/blob - lisp/progmodes/sql.el
(compile-reinitialize-errors): Add help-echo to mouse-highlighted messages.
[gnu-emacs] / lisp / progmodes / sql.el
1 ;;; sql.el --- specialized comint.el for SQL interpreters
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4
5 ;; Author: Alex Schroeder <alex@gnu.org>
6 ;; Maintainer: Alex Schroeder <alex@gnu.org>
7 ;; Version: 1.6.1
8 ;; Keywords: comm languages processes
9
10 ;; This file is part of GNU Emacs.
11
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)
15 ;; any later version.
16
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.
21
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.
26
27 ;;; Commentary:
28
29 ;; Please send bug reports and bug fixes to the mailing list at
30 ;; sql.el@gnu.org. If you want to subscribe to the mailing list, send
31 ;; mail to sql.el-request@gnu.org with `subscribe sql.el FIRSTNAME
32 ;; LASTNAME' in the mail body.
33
34 ;; This file provides a sql-mode and a sql-interactive-mode. My goals
35 ;; were two simple modes providing syntactic hilighting. The
36 ;; interactive mode had to provide a command-line history; the other
37 ;; mode had to provide "send region/buffer to SQL interpreter"
38 ;; functions. "simple" in this context means easy to use, easy to
39 ;; maintain and little or no bells and whistles.
40
41 ;; If anybody feels like extending this sql mode, take a look at the
42 ;; above mentioned modes and write a sqlx-mode on top of this one. If
43 ;; this proves to be difficult, please suggest changes that will
44 ;; facilitate your plans.
45
46 ;; sql-interactive-mode is used to interact with a SQL interpreter
47 ;; process in a SQLi buffer (usually called `*SQL*'). The SQLi buffer
48 ;; is created by calling a SQL interpreter-specific entry function. Do
49 ;; *not* call sql-interactive-mode by itself.
50
51 ;; The list of currently supported interpreters and the corresponding
52 ;; entry function used to create the SQLi buffers is shown with
53 ;; `sql-help' (M-x sql-help).
54
55 ;; Since sql-interactive-mode is built on top of the general
56 ;; command-interpreter-in-a-buffer mode (comint mode), it shares a
57 ;; common base functionality, and a common set of bindings, with all
58 ;; modes derived from comint mode. This makes these modes easier to
59 ;; use.
60
61 ;; sql-mode can be used to keep editing SQL statements. The SQL
62 ;; statements can be sent to the SQL process in the SQLi buffer.
63
64 ;; For documentation on the functionality provided by comint mode, and
65 ;; the hooks available for customizing it, see the file `comint.el'.
66
67 ;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and
68 ;; `imenu-add-menubar-index'.
69
70 ;;; Requirements for Emacs 19.34:
71
72 ;; If you are using Emacs 19.34, you will have to get and install
73 ;; the file regexp-opt.el
74 ;; <URL:ftp://ftp.ifi.uio.no/pub/emacs/emacs-20.3/lisp/emacs-lisp/regexp-opt.el>
75 ;; and the custom package
76 ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>.
77
78 ;;; Bugs:
79
80 ;; Using sql-ms (isql by Microsoft): When commands with syntax errors
81 ;; or execution errors are executed, there is no server feedback.
82 ;; This happens in stored procedures for example. The server messages
83 ;; only appear after the process is exited. This makes things
84 ;; somewhat unreliable.
85
86 ;; ChangeLog available on request.
87
88 ;;; To Do:
89
90 ;; Add better hilight support for other brands; there is a bias towards
91 ;; Oracle because that's what I use at work. Anybody else just send in
92 ;; your lists of reserved words, keywords and builtin functions! As
93 ;; long as I don't receive any feedback, everything is hilighted with
94 ;; ANSI keywords only. I received the list of ANSI keywords from a
95 ;; user; if you know of any changes, let me know.
96
97 ;; Add different hilighting levels.
98
99 ;;; Thanks to all the people who helped me out:
100
101 ;; Kai Blauberg <kai.blauberg@metla.fi>
102 ;; <ibalaban@dalet.com>
103 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il>
104 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
105 ;; nino <nino@inform.dk>
106 ;; Berend de Boer <berend@pobox.com>
107
108 \f
109
110 ;;; Code:
111
112 (require 'comint)
113 ;; Need the following to allow GNU Emacs 19 to compile the file.
114 (require 'regexp-opt)
115 (require 'custom)
116
117 ;;; Allow customization
118
119 (defgroup SQL nil
120 "Running a SQL interpreter from within Emacs buffers"
121 :version "20.4"
122 :group 'processes)
123
124 ;; These three variables will be used as defaults, if set.
125
126 (defcustom sql-user ""
127 "*Default username."
128 :type 'string
129 :group 'SQL)
130
131 (defcustom sql-password ""
132 "*Default password.
133
134 Storing your password in a textfile such as ~/.emacs could be dangerous.
135 Customizing your password will store it in your ~/.emacs file."
136 :type 'string
137 :group 'SQL)
138
139 (defcustom sql-database ""
140 "*Default database."
141 :type 'string
142 :group 'SQL)
143
144 (defcustom sql-server ""
145 "*Default server or host."
146 :type 'string
147 :group 'SQL)
148
149 ;; misc customization of sql.el behaviour
150
151 (defcustom sql-electric-stuff nil
152 "Treat some input as electric.
153 If set to the symbol `semicolon', then hitting `;' will send current
154 input in the SQLi buffer to the process.
155 If set to the symbol `go', then hitting `go' on a line by itself will
156 send current input in the SQLi buffer to the process.
157 If set to nil, then you must use \\[comint-send-input] in order to send
158 current input in the SQLi buffer to the process."
159 :type '(choice (const :tag "Nothing" nil)
160 (const :tag "The semikolon `;'" semicolon)
161 (const :tag "The string `go' by itself" go))
162 :version "20.8"
163 :group 'SQL)
164
165 (defcustom sql-pop-to-buffer-after-send-region nil
166 "*If t, pop to the buffer SQL statements are sent to.
167
168 After a call to `sql-send-region' or `sql-send-buffer',
169 the window is split and the SQLi buffer is shown. If this
170 variable is not nil, that buffer's window will be selected
171 by calling `pop-to-buffer'. If this variable is nil, that
172 buffer is shown using `display-buffer'."
173 :type 'boolean
174 :group 'SQL)
175
176 ;; imenu support for sql-mode.
177
178 (defvar sql-imenu-generic-expression
179 '(("Tables" "^\\s-*create\\s-+table\\s-+\\(\\w+\\)" 1)
180 ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1))
181 "Define interesting points in the SQL buffer for `imenu'.
182
183 This is used to set `imenu-generic-expression' when SQL mode is
184 entered. Subsequent changes to sql-imenu-generic-expression will not
185 affect existing SQL buffers because imenu-generic-expression is a
186 local variable.")
187
188 ;; history file
189
190 (defcustom sql-input-ring-file-name nil
191 "*If non-nil, name of the file to read/write input history.
192
193 You have to set this variable if you want the history of your commands
194 saved from one Emacs session to the next. If this variable is set,
195 exiting the SQL interpreter in an SQLi buffer will write the input
196 history to the specified file. Starting a new process in a SQLi buffer
197 will read the input history from the specified file.
198
199 This is used to initialize `comint-input-ring-file-name'.
200
201 Note that the size of the input history is determined by the variable
202 `comint-input-ring-size'."
203 :type '(choice (const :tag "none" nil)
204 (file))
205 :group 'SQL)
206
207 (defcustom sql-input-ring-separator "\n--\n"
208 "*Separator between commands in the history file.
209
210 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
212 the input ring is initialized from a history file.
213
214 This variable used to initialize `comint-input-ring-separator'.
215 `comint-input-ring-separator' is part of Emacs 21; if your Emacs
216 does not have it, setting `sql-input-ring-separator' will have no
217 effect. In that case multiline commands will be split into several
218 commands when the input history is read, as if you had set
219 `sql-input-ring-separator' to \"\\n\"."
220 :type 'string
221 :group 'SQL)
222
223 ;; The usual hooks
224
225 (defcustom sql-interactive-mode-hook '()
226 "*Hook for customizing `sql-interactive-mode'."
227 :type 'hook
228 :group 'SQL)
229
230 (defcustom sql-mode-hook '()
231 "*Hook for customizing `sql-mode'."
232 :type 'hook
233 :group 'SQL)
234
235 (defcustom sql-set-sqli-hook '()
236 "*Hook for reacting to changes of `sql-buffer'.
237
238 This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
239 is changed."
240 :type 'hook
241 :group 'SQL)
242
243 ;; Customization for Oracle
244
245 (defcustom sql-oracle-program "sqlplus"
246 "*Command to start sqlplus by Oracle.
247
248 Starts `sql-interactive-mode' after doing some setup.
249
250 Under NT, \"sqlplus\" usually starts the sqlplus \"GUI\". In order to
251 start the sqlplus console, use \"plus33\" or something similar. You
252 will find the file in your Orant\\bin directory.
253
254 The program can also specify a TCP connection. See `make-comint'."
255 :type 'file
256 :group 'SQL)
257
258 (defcustom sql-oracle-options nil
259 "*List of additional options for `sql-oracle-program'."
260 :type '(repeat string)
261 :version "20.8"
262 :group 'SQL)
263
264 ;; Customization for MySql
265
266 (defcustom sql-mysql-program "mysql"
267 "*Command to start mysql by TcX.
268
269 Starts `sql-interactive-mode' after doing some setup.
270
271 The program can also specify a TCP connection. See `make-comint'."
272 :type 'file
273 :group 'SQL)
274
275 (defcustom sql-mysql-options nil
276 "*List of additional options for `sql-mysql-program'.
277 The following list of options is reported to make things work
278 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
279 :type '(repeat string)
280 :version "20.8"
281 :group 'SQL)
282
283 ;; Customization for Solid
284
285 (defcustom sql-solid-program "solsql"
286 "*Command to start SOLID SQL Editor.
287
288 Starts `sql-interactive-mode' after doing some setup.
289
290 The program can also specify a TCP connection. See `make-comint'."
291 :type 'file
292 :group 'SQL)
293
294 ;; Customization for SyBase
295
296 (defcustom sql-sybase-program "isql"
297 "*Command to start isql by SyBase.
298
299 Starts `sql-interactive-mode' after doing some setup.
300
301 The program can also specify a TCP connection. See `make-comint'."
302 :type 'file
303 :group 'SQL)
304
305 (defcustom sql-sybase-options nil
306 "*List of additional options for `sql-sybase-program'.
307 Some versions of isql might require the -n option in order to work."
308 :type '(repeat string)
309 :version "20.8"
310 :group 'SQL)
311
312 ;; Customization for Informix
313
314 (defcustom sql-informix-program "dbaccess"
315 "*Command to start dbaccess by Informix.
316
317 Starts `sql-interactive-mode' after doing some setup.
318
319 The program can also specify a TCP connection. See `make-comint'."
320 :type 'file
321 :group 'SQL)
322
323 ;; Customization for Ingres
324
325 (defcustom sql-ingres-program "sql"
326 "*Command to start sql by Ingres.
327
328 Starts `sql-interactive-mode' after doing some setup.
329
330 The program can also specify a TCP connection. See `make-comint'."
331 :type 'file
332 :group 'SQL)
333
334 ;; Customization for Microsoft
335
336 (defcustom sql-ms-program "isql"
337 "*Command to start isql by Microsoft.
338
339 Starts `sql-interactive-mode' after doing some setup.
340
341 The program can also specify a TCP connection. See `make-comint'."
342 :type 'file
343 :group 'SQL)
344
345 ;; Customization for Postgres
346
347 (defcustom sql-postgres-program "psql"
348 "Command to start psql by Postgres.
349
350 Starts `sql-interactive-mode' after doing some setup.
351
352 The program can also specify a TCP connection. See `make-comint'."
353 :type 'file
354 :group 'SQL)
355
356 (defcustom sql-postgres-options '("-P" "pager=off")
357 "*List of additional options for `sql-postgres-program'.
358 The default setting includes the -P option which breaks
359 older versions of the psql client (such as version 6.5.3).
360 The -P option is equivalent to the --pset option.
361 If you want the psql to prompt you for a user name, add the
362 string \"-u\" to the list of options."
363 :type '(repeat string)
364 :version "20.8"
365 :group 'SQL)
366
367 ;; Customization for Interbase
368
369 (defcustom sql-interbase-program "isql"
370 "*Command to start isql by Interbase.
371
372 Starts `sql-interactive-mode' after doing some setup.
373
374 The program can also specify a TCP connection. See `make-comint'."
375 :type 'file
376 :group 'SQL)
377
378 (defcustom sql-interbase-options nil
379 "*List of additional options for `sql-interbase-program'."
380 :type '(repeat string)
381 :version "20.8"
382 :group 'SQL)
383
384 ;; Customization for DB2
385
386 (defcustom sql-db2-program "db2"
387 "*Command to start db2 by IBM.
388
389 Starts `sql-interactive-mode' after doing some setup.
390
391 The program can also specify a TCP connection. See `make-comint'."
392 :type 'file
393 :group 'SQL)
394
395 (defcustom sql-db2-options nil
396 "*List of additional options for `sql-db2-program'."
397 :type '(repeat string)
398 :version "20.8"
399 :group 'SQL)
400
401 \f
402
403 ;;; Variables which do not need customization
404
405 (defvar sql-user-history nil
406 "History of usernames used.")
407
408 (defvar sql-database-history nil
409 "History of databases used.")
410
411 (defvar sql-server-history nil
412 "History of servers used.")
413
414 ;; Passwords are not kept in a history.
415
416 (defvar sql-buffer nil
417 "Current SQLi buffer.
418
419 The global value of sql-buffer is the name of the latest SQLi buffer
420 created. Any SQL buffer created will make a local copy of this value.
421 See `sql-interactive-mode' for more on multiple sessions. If you want
422 to change the SQLi buffer a SQL mode sends its SQL strings to, change
423 the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
424
425 (defvar sql-prompt-regexp nil
426 "Prompt used to initialize `comint-prompt-regexp'.
427
428 You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.")
429
430 (defvar sql-prompt-length 0
431 "Prompt used to set `left-margin' in `sql-interactive-mode'.
432
433 You can change it on `sql-interactive-mode-hook'.")
434
435 (defvar sql-alternate-buffer-name nil
436 "Buffer-local string used to possibly rename the SQLi buffer.
437
438 Used by `sql-rename-buffer'.")
439
440 ;; Keymap for sql-interactive-mode.
441
442 (defvar sql-interactive-mode-map
443 (let ((map (make-sparse-keymap)))
444 (if (functionp 'set-keymap-parent)
445 (set-keymap-parent map comint-mode-map); Emacs
446 (set-keymap-parents map (list comint-mode-map))); XEmacs
447 (if (functionp 'set-keymap-name)
448 (set-keymap-name map 'sql-interactive-mode-map)); XEmacs
449 (define-key map (kbd "C-j") 'sql-accumulate-and-indent)
450 (define-key map (kbd "C-c C-w") 'sql-copy-column)
451 (define-key map (kbd "O") 'sql-magic-go)
452 (define-key map (kbd "o") 'sql-magic-go)
453 (define-key map (kbd ";") 'sql-magic-semicolon)
454 map)
455 "Mode map used for `sql-interactive-mode'.
456 Based on `comint-mode-map'.")
457
458 ;; Keymap for sql-mode.
459
460 (defvar sql-mode-map
461 (let ((map (make-sparse-keymap)))
462 (define-key map (kbd "C-c C-c") 'sql-send-paragraph)
463 (define-key map (kbd "C-c C-r") 'sql-send-region)
464 (define-key map (kbd "C-c C-b") 'sql-send-buffer)
465 map)
466 "Mode map used for `sql-mode'.")
467
468 ;; easy menu for sql-mode.
469
470 (easy-menu-define
471 sql-mode-menu sql-mode-map
472 "Menu for `sql-mode'."
473 '("SQL"
474 ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer)
475 (get-buffer-process sql-buffer))]
476 ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs
477 mark-active)
478 (mark)); XEmacs
479 (buffer-live-p sql-buffer)
480 (get-buffer-process sql-buffer))]
481 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)
482 (get-buffer-process sql-buffer))]
483 ["Show SQLi buffer" sql-show-sqli-buffer t]
484 ["Set SQLi buffer" sql-set-sqli-buffer t]
485 ["Pop to SQLi buffer after send"
486 sql-toggle-pop-to-buffer-after-send-region
487 :style toggle
488 :selected sql-pop-to-buffer-after-send-region]
489 ("Highlighting"
490 ["ANSI SQL keywords" sql-highlight-ansi-keywords t]
491 ["Oracle keywords" sql-highlight-oracle-keywords t]
492 ["Postgres keywords" sql-highlight-postgres-keywords t])))
493
494 ;; easy menu for sql-interactive-mode.
495
496 (easy-menu-define
497 sql-interactive-mode-menu sql-interactive-mode-map
498 "Menu for `sql-interactive-mode'."
499 '("SQL"
500 ["Rename Buffer" sql-rename-buffer t]))
501
502 ;; Abbreviations -- if you want more of them, define them in your
503 ;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too.
504
505 (defvar sql-mode-abbrev-table nil
506 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")
507 (if sql-mode-abbrev-table
508 ()
509 (let ((wrapper))
510 (define-abbrev-table 'sql-mode-abbrev-table ())
511 (define-abbrev sql-mode-abbrev-table "ins" "insert" nil)
512 (define-abbrev sql-mode-abbrev-table "upd" "update" nil)
513 (define-abbrev sql-mode-abbrev-table "del" "delete" nil)
514 (define-abbrev sql-mode-abbrev-table "sel" "select" nil)))
515
516 ;; Syntax Table
517
518 (defvar sql-mode-syntax-table
519 (let ((table (make-syntax-table)))
520 ;; C-style comments /**/ (see elisp manual "Syntax Flags"))
521 (modify-syntax-entry ?/ ". 14" table)
522 (modify-syntax-entry ?* ". 23" table)
523 ;; double-dash starts comment
524 (if (string-match "XEmacs\\|Lucid" emacs-version)
525 (modify-syntax-entry ?- ". 56" table)
526 (modify-syntax-entry ?- ". 12b" table))
527 ;; newline and formfeed end coments
528 (modify-syntax-entry ?\n "> b" table)
529 (modify-syntax-entry ?\f "> b" table)
530 ;; single quotes (') quotes delimit strings
531 (modify-syntax-entry ?' "\"" table)
532 table)
533 "Syntax table used in `sql-mode' and `sql-interactive-mode'.")
534
535 ;; Font lock support
536
537 (defvar sql-mode-ansi-font-lock-keywords nil
538 "ANSI SQL keywords used by font-lock.
539
540 This variable is used by `sql-mode' and `sql-interactive-mode'. The
541 regular expressions are created during compilation by calling the
542 function `regexp-opt'. Therefore, take a look at the source before
543 you define your own sql-mode-ansi-font-lock-keywords. You may want to
544 add functions and PL/SQL keywords.")
545 (if sql-mode-ansi-font-lock-keywords
546 ()
547 (let ((ansi-keywords (eval-when-compile
548 (concat "\\b"
549 (regexp-opt '(
550 "authorization" "avg" "begin" "close" "cobol" "commit"
551 "continue" "count" "declare" "double" "end" "escape"
552 "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"
553 "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli"
554 "precision" "primary" "procedure" "references" "rollback"
555 "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work") t) "\\b")))
556 (ansi-reserved-words (eval-when-compile
557 (concat "\\b"
558 (regexp-opt '(
559 "all" "and" "any" "as" "asc" "between" "by" "check" "create"
560 "current" "default" "delete" "desc" "distinct" "exists" "float" "for"
561 "from" "grant" "group" "having" "in" "insert" "into" "is"
562 "like" "not" "null" "of" "on" "option" "or" "order" "privileges"
563 "public" "select" "set" "table" "to" "union" "unique"
564 "update" "user" "values" "view" "where" "with") t) "\\b")))
565 (ansi-types (eval-when-compile
566 (concat "\\b"
567 (regexp-opt '(
568 ;; ANSI Keywords that look like types
569 "character" "cursor" "dec" "int" "real"
570 ;; ANSI Reserved Word that look like types
571 "char" "integer" "smallint" ) t) "\\b"))))
572 (setq sql-mode-ansi-font-lock-keywords
573 (list (cons ansi-keywords 'font-lock-function-name-face)
574 (cons ansi-reserved-words 'font-lock-keyword-face)
575 (cons ansi-types 'font-lock-type-face)))))
576
577 (defvar sql-mode-oracle-font-lock-keywords nil
578 "Oracle SQL keywords used by font-lock.
579
580 This variable is used by `sql-mode' and `sql-interactive-mode'. The
581 regular expressions are created during compilation by calling the
582 function `regexp-opt'. Therefore, take a look at the source before
583 you define your own sql-mode-oracle-font-lock-keywords. You may want
584 to add functions and PL/SQL keywords.")
585 (if sql-mode-oracle-font-lock-keywords
586 ()
587 (let ((oracle-keywords (eval-when-compile
588 (concat "\\b"
589 (regexp-opt '(
590 "admin" "after" "allocate" "analyze" "archive" "archivelog" "backup"
591 "become" "before" "block" "body" "cache" "cancel" "cascade" "change"
592 "checkpoint" "compile" "constraint" "constraints" "contents"
593 "controlfile" "cycle" "database" "datafile" "dba" "disable" "dismount"
594 "dump" "each" "else" "elsif" "enable" "events" "except" "exceptions"
595 "execute" "exit" "explain" "extent" "externally" "false" "flush" "force"
596 "freelist" "freelists" "function" "groups" "if" "including" "initrans"
597 "instance" "layer" "link" "lists" "logfile" "loop" "manage" "manual"
598 "maxdatafiles" "maxinistances" "maxlogfiles" "maxloghistory"
599 "maxlogmembers" "maxtrans" "maxvalue" "minextents" "minvalue" "mount"
600 "new" "next" "noarchivelog" "nocache" "nocycle" "nomaxvalue"
601 "nominvalue" "none" "noorder" "noresetlogs" "normal" "nosort" "off"
602 "old" "only" "optimal" "others" "out" "own" "package" "parallel"
603 "pctincrease" "pctused" "plan" "pragma" "private" "profile" "quota"
604 "raise" "read" "recover" "referencing" "resetlogs" "restrict_references"
605 "restricted" "return" "returning" "reuse" "rnds" "rnps" "role" "roles"
606 "savepoint" "scn" "segment" "sequence" "shared" "snapshot" "sort"
607 "statement_id" "statistics" "stop" "storage" "subtype" "switch" "system"
608 "tables" "tablespace" "temporary" "thread" "time" "tracing"
609 "transaction" "triggers" "true" "truncate" "type" "under" "unlimited"
610 "until" "use" "using" "when" "while" "wnds" "wnps" "write") t) "\\b")))
611 (oracle-warning-words (eval-when-compile
612 (concat "\\b"
613 (regexp-opt '(
614 "cursor_already_open" "dup_val_on_index" "exception" "invalid_cursor"
615 "invalid_number" "login_denied" "no_data_found" "not_logged_on"
616 "notfound" "others" "pragma" "program_error" "storage_error"
617 "timeout_on_resource" "too_many_rows" "transaction_backed_out"
618 "value_error" "zero_divide") t) "\\b")))
619 (oracle-reserved-words (eval-when-compile
620 (concat "\\b"
621 (regexp-opt '(
622 "access" "add" "alter" "audit" "cluster" "column" "comment" "compress"
623 "connect" "drop" "else" "exclusive" "file" "grant"
624 "identified" "immediate" "increment" "index" "initial" "intersect"
625 "level" "lock" "long" "maxextents" "minus" "mode" "modify" "noaudit"
626 "nocompress" "nowait" "number" "offline" "online" "pctfree" "prior"
627 "raw" "rename" "resource" "revoke" "row" "rowlabel" "rownum"
628 "rows" "session" "share" "size" "start" "successful" "synonym" "sysdate"
629 "then" "trigger" "uid" "validate" "whenever") t) "\\b")))
630 (oracle-types (eval-when-compile
631 (concat "\\b"
632 (regexp-opt '(
633 ;; Oracle Keywords that look like types
634 ;; Oracle Reserved Words that look like types
635 "binary_integer" "blob" "boolean" "constant" "date" "decimal" "rowid"
636 "varchar" "varchar2") t) "\\b")))
637 (oracle-builtin-functions (eval-when-compile
638 (concat "\\b"
639 (regexp-opt '(
640 ;; Misc Oracle builtin functions
641 "abs" "add_months" "ascii" "avg" "ceil" "chartorowid" "chr" "concat"
642 "convert" "cos" "cosh" "count" "currval" "decode" "dump" "exp" "floor"
643 "glb" "greatest" "greatest_lb" "hextoraw" "initcap" "instr" "instrb"
644 "last_day" "least" "least_ub" "length" "lengthb" "ln" "log" "lower"
645 "lpad" "ltrim" "lub" "max" "min" "mod" "months_between" "new_time"
646 "next_day" "nextval" "nls_initcap" "nls_lower" "nls_upper" "nlssort"
647 "nvl" "power" "rawtohex" "replace" "round" "rowidtochar" "rpad"
648 "rtrim" "sign" "sin" "sinh" "soundex" "sqlcode" "sqlerrm" "sqrt"
649 "stddev" "sum" "substr" "substrb" "tan" "tanh" "to_char"
650 "to_date" "to_label" "to_multi_byte" "to_number" "to_single_byte"
651 "translate" "trim" "trunc" "uid" "upper" "userenv" "variance" "vsize") t) "\\b"))))
652 (setq sql-mode-oracle-font-lock-keywords
653 (append sql-mode-ansi-font-lock-keywords
654 (list (cons oracle-keywords 'font-lock-function-name-face)
655 (cons oracle-warning-words 'font-lock-warning-face)
656 (cons oracle-reserved-words 'font-lock-keyword-face)
657 ;; XEmacs doesn't have font-lock-builtin-face
658 (if (string-match "XEmacs\\|Lucid" emacs-version)
659 (cons oracle-builtin-functions 'font-lock-preprocessor-face)
660 ;; GNU Emacs 19 doesn't have it either
661 (if (string-match "GNU Emacs 19" emacs-version)
662 (cons oracle-builtin-functions 'font-lock-function-name-face)
663 ;; Emacs
664 (cons oracle-builtin-functions 'font-lock-builtin-face)))
665 (cons oracle-types 'font-lock-type-face))))))
666
667 (defvar sql-mode-postgres-font-lock-keywords nil
668 "Postgres SQL keywords used by font-lock.
669
670 This variable is used by `sql-mode' and `sql-interactive-mode'. The
671 regular expressions are created during compilation by calling the
672 function `regexp-opt'. Therefore, take a look at the source before
673 you define your own sql-mode-postgres-font-lock-keywords.")
674
675 (if sql-mode-postgres-font-lock-keywords
676 ()
677 (let ((postgres-reserved-words (eval-when-compile
678 (concat "\\b"
679 (regexp-opt '(
680 "language"
681 ) t) "\\b")))
682 (postgres-types (eval-when-compile
683 (concat "\\b"
684 (regexp-opt '(
685 "bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date"
686 "float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path"
687 "point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar"
688 ) t)"\\b")))
689 (postgres-builtin-functions (eval-when-compile
690 (concat "\\b"
691 (regexp-opt '(
692 ;; Misc Postgres builtin functions
693 "abstime" "age" "area" "box" "center" "date_part" "date_trunc"
694 "datetime" "dexp" "diameter" "dpow" "float" "float4" "height"
695 "initcap" "integer" "isclosed" "isfinite" "isoldpath" "isopen"
696 "length" "lower" "lpad" "ltrim" "pclose" "point" "points" "popen"
697 "position" "radius" "reltime" "revertpoly" "rpad" "rtrim" "substr"
698 "substring" "text" "timespan" "translate" "trim" "upgradepath"
699 "upgradepoly" "upper" "varchar" "width"
700 ) t) "\\b"))))
701 (setq sql-mode-postgres-font-lock-keywords
702 (append sql-mode-ansi-font-lock-keywords
703 (list (cons postgres-reserved-words 'font-lock-keyword-face)
704 ;; XEmacs doesn't have 'font-lock-builtin-face
705 (if (string-match "XEmacs\\|Lucid" emacs-version)
706 (cons postgres-builtin-functions 'font-lock-preprocessor-face)
707 ;; Emacs
708 (cons postgres-builtin-functions 'font-lock-builtin-face))
709 (cons postgres-types 'font-lock-type-face))))))
710
711
712 (defvar sql-mode-font-lock-keywords sql-mode-ansi-font-lock-keywords
713 "SQL keywords used by font-lock.
714
715 This variable defaults to `sql-mode-ansi-font-lock-keywords'. This is
716 used for the default `font-lock-defaults' value in `sql-mode'. This
717 can be changed by some entry functions to provide more hilighting.")
718
719 \f
720
721 ;;; Functions to switch highlighting
722
723 (defun sql-highlight-oracle-keywords ()
724 "Highlight Oracle keywords.
725 Basically, this just sets `font-lock-keywords' appropriately."
726 (interactive)
727 (setq font-lock-keywords sql-mode-oracle-font-lock-keywords)
728 (font-lock-fontify-buffer))
729
730 (defun sql-highlight-postgres-keywords ()
731 "Highlight Postgres keywords.
732 Basically, this just sets `font-lock-keywords' appropriately."
733 (interactive)
734 (setq font-lock-keywords sql-mode-postgres-font-lock-keywords)
735 (font-lock-fontify-buffer))
736
737 (defun sql-highlight-ansi-keywords ()
738 "Highlight ANSI SQL keywords.
739 Basically, this just sets `font-lock-keywords' appropriately."
740 (interactive)
741 (setq font-lock-keywords sql-mode-ansi-font-lock-keywords)
742 (font-lock-fontify-buffer))
743
744 \f
745
746 ;;; Compatibility functions
747
748 (if (not (fboundp 'comint-line-beginning-position))
749 ;; comint-line-beginning-position is defined in Emacs 21
750 (defun comint-line-beginning-position ()
751 "Returns the buffer position of the beginning of the line, after any prompt.
752 The prompt is assumed to be any text at the beginning of the line matching
753 the regular expression `comint-prompt-regexp', a buffer local variable."
754 (save-excursion (comint-bol nil) (point))))
755
756 \f
757
758 ;;; Small functions
759
760 (defun sql-magic-go (arg)
761 "Insert \"o\" and call `comint-send-input'.
762 `sql-electric-stuff' must be the symbol `go'."
763 (interactive "P")
764 (self-insert-command (prefix-numeric-value arg))
765 (if (and (equal sql-electric-stuff 'go)
766 (save-excursion
767 (comint-bol nil)
768 (looking-at "go\\b")))
769 (comint-send-input)))
770
771 (defun sql-magic-semicolon (arg)
772 "Insert semicolon and call `comint-send-input'.
773 `sql-electric-stuff' must be the symbol `semicolon'."
774 (interactive "P")
775 (self-insert-command (prefix-numeric-value arg))
776 (if (equal sql-electric-stuff 'semicolon)
777 (comint-send-input)))
778
779 (defun sql-accumulate-and-indent ()
780 "Continue SQL statement on the next line."
781 (interactive)
782 (if (fboundp 'comint-accumulate)
783 (comint-accumulate)
784 (newline))
785 (indent-according-to-mode))
786
787 ;;;###autoload
788 (defun sql-help ()
789 "Show short help for the SQL modes.
790
791 Use an entry function to open an interactive SQL buffer. This buffer is
792 usually named `*SQL*'. The name of the major mode is SQLi.
793
794 Use the following commands to start a specific SQL interpreter:
795
796 PostGres: \\[sql-postgres]
797
798 Other non-free SQL implementations are also supported:
799
800 MySQL: \\[sql-mysql]
801 Solid: \\[sql-solid]
802 Oracle: \\[sql-oracle]
803 Informix: \\[sql-informix]
804 Sybase: \\[sql-sybase]
805 Ingres: \\[sql-ingres]
806 Microsoft: \\[sql-ms]
807 Interbase: \\[sql-interbase]
808
809 But we urge you to choose a free implementation instead of these.
810
811 Once you have the SQLi buffer, you can enter SQL statements in the
812 buffer. The output generated is appended to the buffer and a new prompt
813 is generated. See the In/Out menu in the SQLi buffer for some functions
814 that help you navigate through the buffer, the input history, etc.
815
816 If you have a really complex SQL statement or if you are writing a
817 procedure, you can do this in a separate buffer. Put the new buffer in
818 `sql-mode' by calling \\[sql-mode]. The name of this buffer can be
819 anything. The name of the major mode is SQL.
820
821 In this SQL buffer (SQL mode), you can send the region or the entire
822 buffer to the interactive SQL buffer (SQLi mode). The results are
823 appended to the SQLi buffer without disturbing your SQL buffer."
824 (interactive)
825 (describe-function 'sql-help))
826
827 (defun sql-read-passwd (prompt &optional default)
828 "Read a password using PROMPT.
829 Optional DEFAULT is password to start with. This function calls
830 `read-passwd' if it is available. If not, function
831 `ange-ftp-read-passwd' is called. This should always be available,
832 even in old versions of Emacs."
833 (if (fboundp 'read-passwd)
834 (read-passwd prompt nil default)
835 (unless (fboundp 'ange-ftp-read-passwd)
836 (autoload 'ange-ftp-read-passwd "ange-ftp"))
837 (ange-ftp-read-passwd prompt default)))
838
839 (defun sql-get-login (&rest what)
840 "Get username, password and database from the user.
841
842 The variables `sql-user', `sql-password', `sql-server', and
843 `sql-database' can be customized. They are used as the default values.
844 Usernames, servers and databases are stored in `sql-user-history',
845 `sql-server-history' and `database-history'. Passwords are not stored
846 in a history.
847
848 Parameter WHAT is a list of the arguments passed to this function.
849 The function asks for the username if WHAT contains symbol `user', for
850 the password if it contains symbol `password', for the server if it
851 contains symbol `server', and for the database if it contains symbol
852 `database'.
853
854 In order to ask the user for username, password and database, call the
855 function like this: (sql-get-login 'user 'password 'database)."
856 (interactive)
857 (if (memq 'user what)
858 (setq sql-user
859 (read-from-minibuffer "User: " sql-user nil nil
860 sql-user-history)))
861 (if (memq 'password what)
862 (setq sql-password
863 (sql-read-passwd "Password: " sql-password)))
864 (if (memq 'server what)
865 (setq sql-server
866 (read-from-minibuffer "Server: " sql-server nil nil
867 sql-server-history)))
868 (if (memq 'database what)
869 (setq sql-database
870 (read-from-minibuffer "Database: " sql-database nil nil
871 sql-database-history))))
872
873 (defun sql-find-sqli-buffer ()
874 "Return the current default SQLi buffer or nil.
875 In order to qualify, the SQLi buffer must be alive,
876 be in `sql-interactive-mode' and have a process."
877 (let ((default-buffer (default-value 'sql-buffer)))
878 (if (and (buffer-live-p default-buffer)
879 (get-buffer-process default-buffer))
880 default-buffer
881 (save-excursion
882 (let ((buflist (buffer-list))
883 (found))
884 (while (not (or (null buflist)
885 found))
886 (let ((candidate (car buflist)))
887 (set-buffer candidate)
888 (if (and (equal major-mode 'sql-interactive-mode)
889 (get-buffer-process candidate))
890 (setq found candidate))
891 (setq buflist (cdr buflist))))
892 found)))))
893
894 (defun sql-set-sqli-buffer-generally ()
895 "Set SQLi buffer for all SQL buffers that have none.
896 This function checks all SQL buffers for their SQLi buffer. If their
897 SQLi buffer is nonexistent or has no process, it is set to the current
898 default SQLi buffer. The current default SQLi buffer is determined
899 using `sql-find-sqli-buffer'. If `sql-buffer' is set,
900 `sql-set-sqli-hook' is run."
901 (interactive)
902 (save-excursion
903 (let ((buflist (buffer-list))
904 (default-sqli-buffer (sql-find-sqli-buffer)))
905 (setq-default sql-buffer default-sqli-buffer)
906 (while (not (null buflist))
907 (let ((candidate (car buflist)))
908 (set-buffer candidate)
909 (if (and (equal major-mode 'sql-mode)
910 (not (buffer-live-p sql-buffer)))
911 (progn
912 (setq sql-buffer default-sqli-buffer)
913 (run-hooks 'sql-set-sqli-hook))))
914 (setq buflist (cdr buflist))))))
915
916 (defun sql-set-sqli-buffer ()
917 "Set the SQLi buffer SQL strings are sent to.
918
919 Call this function in a SQL buffer in order to set the SQLi buffer SQL
920 strings are sent to. Calling this function sets `sql-buffer' and runs
921 `sql-set-sqli-hook'.
922
923 If you call it from a SQL buffer, this sets the local copy of
924 `sql-buffer'.
925
926 If you call it from anywhere else, it sets the global copy of
927 `sql-buffer'."
928 (interactive)
929 (let ((default-buffer (sql-find-sqli-buffer)))
930 (if (null default-buffer)
931 (error "There is no suitable SQLi buffer"))
932 (let ((new-buffer
933 (get-buffer
934 (read-buffer "New SQLi buffer: " default-buffer t))))
935 (if (null (get-buffer-process new-buffer))
936 (error "Buffer %s has no process" (buffer-name new-buffer)))
937 (if (null (save-excursion
938 (set-buffer new-buffer)
939 (equal major-mode 'sql-interactive-mode)))
940 (error "Buffer %s is no SQLi buffer" (buffer-name new-buffer)))
941 (if new-buffer
942 (progn
943 (setq sql-buffer new-buffer)
944 (run-hooks 'sql-set-sqli-hook))))))
945
946 (defun sql-show-sqli-buffer ()
947 "Show the name of current SQLi buffer.
948
949 This is the buffer SQL strings are sent to. It is stored in the
950 variable `sql-buffer'. See `sql-help' on how to create such a buffer."
951 (interactive)
952 (if (null (buffer-live-p sql-buffer))
953 (message "%s has no SQLi buffer set." (buffer-name (current-buffer)))
954 (if (null (get-buffer-process sql-buffer))
955 (message "Buffer %s has no process." (buffer-name sql-buffer))
956 (message "Current SQLi buffer is %s." (buffer-name sql-buffer)))))
957
958 (defun sql-make-alternate-buffer-name ()
959 "Return a string that can be used to rename a SQLi buffer.
960
961 This is used to set `sql-alternate-buffer-name' within
962 `sql-interactive-mode'."
963 (concat (if (string= "" sql-user)
964 (if (string= "" (user-login-name))
965 ()
966 (concat (user-login-name) "/"))
967 (concat sql-user "/"))
968 (if (string= "" sql-database)
969 (if (string= "" sql-server)
970 (system-name)
971 sql-server)
972 sql-database)))
973
974 (defun sql-rename-buffer ()
975 "Renames a SQLi buffer."
976 (interactive)
977 (rename-buffer (format "*SQL: %s*" sql-alternate-buffer-name) t))
978
979 (defun sql-copy-column ()
980 "Copy current column to the end of buffer.
981 Inserts SELECT or commas if appropriate."
982 (interactive)
983 (let ((column))
984 (save-excursion
985 (setq column (buffer-substring
986 (progn (forward-char 1) (backward-sexp 1) (point))
987 (progn (forward-sexp 1) (point))))
988 (goto-char (point-max))
989 (let ((bol (comint-line-beginning-position)))
990 (cond
991 ;; if empty command line, insert SELECT
992 ((= bol (point))
993 (insert "SELECT "))
994 ;; else if appending to INTO .* (, SELECT or ORDER BY, insert a comma
995 ((save-excursion
996 (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+"
997 bol t))
998 (insert ", "))
999 ;; else insert a space
1000 (t
1001 (if (eq (preceding-char) ? )
1002 nil
1003 (insert " ")))))
1004 ;; in any case, insert the column
1005 (insert column)
1006 (message "%s" column))))
1007
1008 ;; On NT, SQL*Plus for Oracle turns on full buffering for stdout if it
1009 ;; is not attached to a character device; therefore placeholder
1010 ;; replacement by SQL*Plus is fully buffered. The workaround lets
1011 ;; Emacs query for the placeholders.
1012
1013 (defvar sql-placeholder-history nil
1014 "History of placeholder values used.")
1015
1016 (defun sql-query-placeholders-and-send (proc string)
1017 "Send to PROC input STRING, maybe replacing placeholders.
1018 Placeholders are words starting with and ampersand like &this.
1019 This function is used for `comint-input-sender' if using `sql-oracle' on NT."
1020 (while (string-match "&\\(\\sw+\\)" string)
1021 (setq string (replace-match
1022 (read-from-minibuffer
1023 (format "Enter value for %s: " (match-string 1 string))
1024 nil nil nil sql-placeholder-history)
1025 t t string)))
1026 (comint-send-string proc string)
1027 (comint-send-string proc "\n"))
1028
1029 ;; Using DB2 interactively, newlines must be escaped with " \".
1030 ;; The space before the backslash is relevant.
1031 (defun sql-escape-newlines-and-send (proc string)
1032 "Send to PROC input STRING, escaping newlines if necessary.
1033 Every newline in STRING will be preceded with a space and a backslash."
1034 (let ((result "") (start 0) mb me)
1035 (while (string-match "\n" string start)
1036 (setq mb (match-beginning 0)
1037 me (match-end 0))
1038 (if (and (> mb 1)
1039 (string-equal " \\" (substring string (- mb 2) mb)))
1040 (setq result (concat result (substring string start me)))
1041 (setq result (concat result (substring string start mb) " \\\n")))
1042 (setq start me))
1043 (setq result (concat result (substring string start)))
1044 (comint-send-string proc result)
1045 (comint-send-string proc "\n")))
1046
1047 \f
1048
1049 ;;; Sending the region to the SQLi buffer.
1050
1051 (defun sql-send-region (start end)
1052 "Send a region to the SQL process."
1053 (interactive "r")
1054 (if (buffer-live-p sql-buffer)
1055 (save-excursion
1056 (comint-send-region sql-buffer start end)
1057 (if (string-match "\n$" (buffer-substring start end))
1058 ()
1059 (comint-send-string sql-buffer "\n"))
1060 (message "Sent string to buffer %s." (buffer-name sql-buffer))
1061 (if sql-pop-to-buffer-after-send-region
1062 (pop-to-buffer sql-buffer)
1063 (display-buffer sql-buffer)))
1064 (message "No SQL process started.")))
1065
1066 (defun sql-send-paragraph ()
1067 "Send the current paragraph to the SQL process."
1068 (interactive)
1069 (let ((start (save-excursion
1070 (backward-paragraph)
1071 (point)))
1072 (end (save-excursion
1073 (forward-paragraph)
1074 (point))))
1075 (sql-send-region start end)))
1076
1077 (defun sql-send-buffer ()
1078 "Send the buffer contents to the SQL process."
1079 (interactive)
1080 (sql-send-region (point-min) (point-max)))
1081
1082 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value)
1083 "Toggle `sql-pop-to-buffer-after-send-region'.
1084
1085 If given the optional parameter VALUE, sets
1086 sql-toggle-pop-to-buffer-after-send-region to VALUE."
1087 (interactive "P")
1088 (if value
1089 (setq sql-pop-to-buffer-after-send-region value)
1090 (setq sql-pop-to-buffer-after-send-region
1091 (null sql-pop-to-buffer-after-send-region ))))
1092
1093 \f
1094
1095 ;;; SQL mode -- uses SQL interactive mode
1096
1097 ;;;###autoload
1098 (defun sql-mode ()
1099 "Major mode to edit SQL.
1100
1101 You can send SQL statements to the SQLi buffer using
1102 \\[sql-send-region]. Such a buffer must exist before you can do this.
1103 See `sql-help' on how to create SQLi buffers.
1104
1105 \\{sql-mode-map}
1106 Customization: Entry to this mode runs the `sql-mode-hook'.
1107
1108 When you put a buffer in SQL mode, the buffer stores the last SQLi
1109 buffer created as its destination in the variable `sql-buffer'. This
1110 will be the buffer \\[sql-send-region] sends the region to. If this
1111 SQLi buffer is killed, \\[sql-send-region] is no longer able to
1112 determine where the strings should be sent to. You can set the
1113 value of `sql-buffer' using \\[sql-set-sqli-buffer].
1114
1115 For information on how to create multiple SQLi buffers, see
1116 `sql-interactive-mode'."
1117 (interactive)
1118 (kill-all-local-variables)
1119 (setq major-mode 'sql-mode)
1120 (setq mode-name "SQL")
1121 (use-local-map sql-mode-map)
1122 (if sql-mode-menu
1123 (easy-menu-add sql-mode-menu)); XEmacs
1124 (set-syntax-table sql-mode-syntax-table)
1125 (make-local-variable 'font-lock-defaults)
1126 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
1127 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
1128 ;; will have just one quote. Therefore syntactic hilighting is
1129 ;; disabled for interactive buffers. `_' and `.' are considered part
1130 ;; of words.
1131 (setq font-lock-defaults '(sql-mode-font-lock-keywords
1132 nil t ((?_ . "w") (?. . "w"))))
1133 (make-local-variable 'comment-start)
1134 (setq comment-start "--")
1135 ;; Make each buffer in sql-mode remember the "current" SQLi buffer.
1136 (make-local-variable 'sql-buffer)
1137 ;; Add imenu support for sql-mode. Note that imenu-generic-expression
1138 ;; is buffer-local, so we don't need a local-variable for it. SQL is
1139 ;; case-insensitive, that's why we have to set imenu-case-fold-search.
1140 ;; imenu-syntax-alist makes sure that `_' is considered part of object
1141 ;; names.
1142 (setq imenu-generic-expression sql-imenu-generic-expression
1143 imenu-case-fold-search t
1144 imenu-syntax-alist '(("_" . "w")))
1145 ;; Make `sql-send-paragraph' work on paragraphs that contain indented
1146 ;; lines.
1147 (make-local-variable 'paragraph-separate)
1148 (make-local-variable 'paragraph-start)
1149 (setq paragraph-separate "[\f]*$"
1150 paragraph-start "[\n\f]")
1151 ;; Abbrevs
1152 (setq local-abbrev-table sql-mode-abbrev-table)
1153 (setq abbrev-all-caps 1)
1154 ;; Run hook
1155 (run-hooks 'sql-mode-hook))
1156
1157 \f
1158
1159 ;;; SQL interactive mode
1160
1161 (put 'sql-interactive-mode 'mode-class 'special)
1162
1163 (defun sql-interactive-mode ()
1164 "Major mode to use a SQL interpreter interactively.
1165
1166 Do not call this function by yourself. The environment must be
1167 initialized by an entry function specific for the SQL interpreter. See
1168 `sql-help' for a list of available entry functions.
1169
1170 \\[comint-send-input] after the end of the process' output sends the
1171 text from the end of process to the end of the current line.
1172 \\[comint-send-input] before end of process output copies the current
1173 line minus the prompt to the end of the buffer and sends it.
1174 \\[comint-copy-old-input] just copies the current line.
1175 Use \\[sql-accumulate-and-indent] to enter multi-line statements.
1176
1177 If you want to make multiple SQL buffers, rename the `*SQL*' buffer
1178 using \\[rename-buffer] or \\[rename-uniquely] and start a new process.
1179 See `sql-help' for a list of available entry functions. The last buffer
1180 created by such an entry function is the current SQLi buffer. SQL
1181 buffers will send strings to the SQLi buffer current at the time of
1182 their creation. See `sql-mode' for details.
1183
1184 Sample session using two connections:
1185
1186 1. Create first SQLi buffer by calling an entry function.
1187 2. Rename buffer \"*SQL*\" to \"*Connection 1*\".
1188 3. Create a SQL buffer \"test1.sql\".
1189 4. Create second SQLi buffer by calling an entry function.
1190 5. Rename buffer \"*SQL*\" to \"*Connection 2*\".
1191 6. Create a SQL buffer \"test2.sql\".
1192
1193 Now \\[sql-send-region] in buffer \"test1.sql\" will send the region to
1194 buffer \"*Connection 1*\", \\[sql-send-region] in buffer \"test2.sql\"
1195 will send the region to buffer \"*Connection 2*\".
1196
1197 If you accidentally suspend your process, use \\[comint-continue-subjob]
1198 to continue it. On some operating systems, this will not work because
1199 the signals are not supported.
1200
1201 \\{sql-interactive-mode-map}
1202 Customization: Entry to this mode runs the hooks on `comint-mode-hook'
1203 and `sql-interactive-mode-hook' (in that order). Before each input, the
1204 hooks on `comint-input-filter-functions' are run. After each SQL
1205 interpreter output, the hooks on `comint-output-filter-functions' are
1206 run.
1207
1208 Variable `sql-input-ring-file-name' controls the initialisation of the
1209 input ring history.
1210
1211 Variables `comint-output-filter-functions', a hook, and
1212 `comint-scroll-to-bottom-on-input' and
1213 `comint-scroll-to-bottom-on-output' control whether input and output
1214 cause the window to scroll to the end of the buffer.
1215
1216 If you want to make SQL buffers limited in length, add the function
1217 `comint-truncate-buffer' to `comint-output-filter-functions'.
1218
1219 Here is an example for your .emacs file. It keeps the SQLi buffer a
1220 certain length.
1221
1222 \(add-hook 'sql-interactive-mode-hook
1223 \(function (lambda ()
1224 \(setq comint-output-filter-functions 'comint-truncate-buffer))))
1225
1226 Here is another example. It will always put point back to the statement
1227 you entered, right above the output it created.
1228
1229 \(setq comint-output-filter-functions
1230 \(function (lambda (STR) (comint-show-output))))"
1231 (comint-mode)
1232 (setq comint-prompt-regexp sql-prompt-regexp)
1233 (setq left-margin sql-prompt-length)
1234 (setq major-mode 'sql-interactive-mode)
1235 (setq mode-name "SQLi")
1236 (use-local-map sql-interactive-mode-map)
1237 (if sql-interactive-mode-menu
1238 (easy-menu-add sql-interactive-mode-menu)); XEmacs
1239 (set-syntax-table sql-mode-syntax-table)
1240 (make-local-variable 'font-lock-defaults)
1241 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
1242 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
1243 ;; will have just one quote. Therefore syntactic hilighting is
1244 ;; disabled for interactive buffers. `_' and `.' are considered part
1245 ;; of words.
1246 (setq font-lock-defaults '(sql-mode-font-lock-keywords
1247 t t ((?_ . "w") (?. . "w"))))
1248 ;; Enable commenting and uncommenting of the region.
1249 (make-local-variable 'comment-start)
1250 (setq comment-start "--")
1251 ;; Abbreviation table init and case-insensitive. It is not activatet
1252 ;; by default.
1253 (setq local-abbrev-table sql-mode-abbrev-table)
1254 (setq abbrev-all-caps 1)
1255 ;; Exiting the process will call sql-stop.
1256 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop)
1257 ;; People wanting a different history file for each
1258 ;; buffer/process/client/whatever can change separator and file-name
1259 ;; on the sql-interactive-mode-hook.
1260 (setq comint-input-ring-separator sql-input-ring-separator
1261 comint-input-ring-file-name sql-input-ring-file-name)
1262 ;; Create a usefull name for renaming this buffer later.
1263 (make-local-variable 'sql-alternate-buffer-name)
1264 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name))
1265 ;; User stuff.
1266 (run-hooks 'sql-interactive-mode-hook)
1267 ;; Calling the hook before calling comint-read-input-ring allows users
1268 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook.
1269 (comint-read-input-ring t))
1270
1271 (defun sql-stop (process event)
1272 "Called when the SQL process is stopped.
1273
1274 Writes the input history to a history file using
1275 `comint-write-input-ring' and inserts a short message in the SQL buffer.
1276
1277 This function is a sentinel watching the SQL interpreter process.
1278 Sentinels will always get the two parameters PROCESS and EVENT."
1279 (comint-write-input-ring)
1280 (if (and (eq (current-buffer) sql-buffer)
1281 (not buffer-read-only))
1282 (insert (format "\nProcess %s %s\n" process event))
1283 (message "Process %s %s" process event)))
1284
1285 \f
1286
1287 ;;; Entry functions for different SQL interpreters.
1288
1289 ;;;###autoload
1290 (defun sql-oracle ()
1291 "Run sqlplus by Oracle as an inferior process.
1292
1293 If buffer `*SQL*' exists but no process is running, make a new process.
1294 If buffer exists and a process is running, just switch to buffer
1295 `*SQL*'.
1296
1297 Interpreter used comes from variable `sql-oracle-program'. Login uses
1298 the variables `sql-user', `sql-password', and `sql-database' as
1299 defaults, if set. Additional command line parameters can be stored in
1300 the list `sql-oracle-options'.
1301
1302 The buffer is put in sql-interactive-mode, giving commands for sending
1303 input. See `sql-interactive-mode'.
1304
1305 To specify a coding system for converting non-ASCII characters
1306 in the input and output to the process, use \\[universal-coding-system-argument]
1307 before \\[sql-oracle]. You can also specify this with \\[set-buffer-process-coding-system]
1308 in the SQL buffer, after you start the process.
1309 The default comes from `process-coding-system-alist' and
1310 `default-process-coding-system'.
1311
1312 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1313 (interactive)
1314 (if (comint-check-proc "*SQL*")
1315 (pop-to-buffer "*SQL*")
1316 (sql-get-login 'user 'password 'database)
1317 (message "Login...")
1318 ;; Produce user/password@database construct. Password without user
1319 ;; is meaningless; database without user/password is meaningless,
1320 ;; because "@param" will ask sqlplus to interpret the script
1321 ;; "param".
1322 (let ((parameter nil))
1323 (if (not (string= "" sql-user))
1324 (if (not (string= "" sql-password))
1325 (setq parameter (concat sql-user "/" sql-password))
1326 (setq parameter sql-user)))
1327 (if (and parameter (not (string= "" sql-database)))
1328 (setq parameter (concat parameter "@" sql-database)))
1329 (if parameter
1330 (setq parameter (nconc (list parameter) sql-oracle-options))
1331 (setq parameter sql-oracle-options))
1332 (if parameter
1333 (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil
1334 parameter))
1335 (set-buffer (make-comint "SQL" sql-oracle-program nil))))
1336 (setq sql-prompt-regexp "^SQL> ")
1337 (setq sql-prompt-length 5)
1338 (setq sql-buffer (current-buffer))
1339 ;; set sql-mode-font-lock-keywords to something different before
1340 ;; calling sql-interactive-mode.
1341 (setq sql-mode-font-lock-keywords sql-mode-oracle-font-lock-keywords)
1342 (sql-interactive-mode)
1343 ;; If running on NT, make sure we do placeholder replacement
1344 ;; ourselves. This must come after sql-interactive-mode because all
1345 ;; local variables will be killed, there.
1346 (if (eq window-system 'w32)
1347 (setq comint-input-sender 'sql-query-placeholders-and-send))
1348 (message "Login...done")
1349 (pop-to-buffer sql-buffer)))
1350
1351 \f
1352
1353 ;;;###autoload
1354 (defun sql-sybase ()
1355 "Run isql by SyBase as an inferior process.
1356
1357 If buffer `*SQL*' exists but no process is running, make a new process.
1358 If buffer exists and a process is running, just switch to buffer
1359 `*SQL*'.
1360
1361 Interpreter used comes from variable `sql-sybase-program'. Login uses
1362 the variables `sql-server', `sql-user', `sql-password', and
1363 `sql-database' as defaults, if set. Additional command line parameters
1364 can be stored in the list `sql-sybase-options'.
1365
1366 The buffer is put in sql-interactive-mode, giving commands for sending
1367 input. See `sql-interactive-mode'.
1368
1369 To specify a coding system for converting non-ASCII characters
1370 in the input and output to the process, use \\[universal-coding-system-argument]
1371 before \\[sql-sybase]. You can also specify this with \\[set-buffer-process-coding-system]
1372 in the SQL buffer, after you start the process.
1373 The default comes from `process-coding-system-alist' and
1374 `default-process-coding-system'.
1375
1376 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1377 (interactive)
1378 (if (comint-check-proc "*SQL*")
1379 (pop-to-buffer "*SQL*")
1380 (sql-get-login 'server 'user 'password 'database)
1381 (message "Login...")
1382 ;; Put all parameters to the program (if defined) in a list and call
1383 ;; make-comint.
1384 (let ((params sql-sybase-options))
1385 (if (not (string= "" sql-server))
1386 (setq params (append (list "-S" sql-server) params)))
1387 (if (not (string= "" sql-database))
1388 (setq params (append (list "-D" sql-database) params)))
1389 (if (not (string= "" sql-password))
1390 (setq params (append (list "-P" sql-password) params)))
1391 (if (not (string= "" sql-user))
1392 (setq params (append (list "-U" sql-user) params)))
1393 (set-buffer (apply 'make-comint "SQL" sql-sybase-program
1394 nil params)))
1395 (setq sql-prompt-regexp "^SQL> ")
1396 (setq sql-prompt-length 5)
1397 (setq sql-buffer (current-buffer))
1398 (sql-interactive-mode)
1399 (message "Login...done")
1400 (pop-to-buffer sql-buffer)))
1401
1402 \f
1403
1404 ;;;###autoload
1405 (defun sql-informix ()
1406 "Run dbaccess by Informix as an inferior process.
1407
1408 If buffer `*SQL*' exists but no process is running, make a new process.
1409 If buffer exists and a process is running, just switch to buffer
1410 `*SQL*'.
1411
1412 Interpreter used comes from variable `sql-informix-program'. Login uses
1413 the variable `sql-database' as default, if set.
1414
1415 The buffer is put in sql-interactive-mode, giving commands for sending
1416 input. See `sql-interactive-mode'.
1417
1418 To specify a coding system for converting non-ASCII characters
1419 in the input and output to the process, use \\[universal-coding-system-argument]
1420 before \\[sql-informix]. You can also specify this with \\[set-buffer-process-coding-system]
1421 in the SQL buffer, after you start the process.
1422 The default comes from `process-coding-system-alist' and
1423 `default-process-coding-system'.
1424
1425 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1426 (interactive)
1427 (if (comint-check-proc "*SQL*")
1428 (pop-to-buffer "*SQL*")
1429 (sql-get-login 'database)
1430 (message "Login...")
1431 ;; username and password are ignored.
1432 (if (string= "" sql-database)
1433 (set-buffer (make-comint "SQL" sql-informix-program nil))
1434 (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-")))
1435 (setq sql-prompt-regexp "^SQL> ")
1436 (setq sql-prompt-length 5)
1437 (setq sql-buffer (current-buffer))
1438 (sql-interactive-mode)
1439 (message "Login...done")
1440 (pop-to-buffer sql-buffer)))
1441
1442 \f
1443
1444 ;;;###autoload
1445 (defun sql-mysql ()
1446 "Run mysql by TcX as an inferior process.
1447
1448 Note that the widespread idea that mysql is free software is inaccurate;
1449 its license is too restrictive. We urge you to use PostGres instead.
1450
1451 If buffer `*SQL*' exists but no process is running, make a new process.
1452 If buffer exists and a process is running, just switch to buffer
1453 `*SQL*'.
1454
1455 Interpreter used comes from variable `sql-mysql-program'. Login uses
1456 the variables `sql-user', `sql-password', `sql-database', and
1457 `sql-server' as defaults, if set. Additional command line parameters
1458 can be stored in the list `sql-mysql-options'.
1459
1460 The buffer is put in sql-interactive-mode, giving commands for sending
1461 input. See `sql-interactive-mode'.
1462
1463 To specify a coding system for converting non-ASCII characters
1464 in the input and output to the process, use \\[universal-coding-system-argument]
1465 before \\[sql-mysql]. You can also specify this with \\[set-buffer-process-coding-system]
1466 in the SQL buffer, after you start the process.
1467 The default comes from `process-coding-system-alist' and
1468 `default-process-coding-system'.
1469
1470 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1471 (interactive)
1472 (if (comint-check-proc "*SQL*")
1473 (pop-to-buffer "*SQL*")
1474 (sql-get-login 'user 'password 'database 'server)
1475 (message "Login...")
1476 ;; Put all parameters to the program (if defined) in a list and call
1477 ;; make-comint.
1478 (let ((params))
1479 (if (not (string= "" sql-database))
1480 (setq params (append (list sql-database) params)))
1481 (if (not (string= "" sql-server))
1482 (setq params (append (list (concat "--host=" sql-server)) params)))
1483 (if (not (string= "" sql-password))
1484 (setq params (append (list (concat "--password=" sql-password)) params)))
1485 (if (not (string= "" sql-user))
1486 (setq params (append (list (concat "--user=" sql-user)) params)))
1487 (if (not (null sql-mysql-options))
1488 (setq params (append sql-mysql-options params)))
1489 (set-buffer (apply 'make-comint "SQL" sql-mysql-program
1490 nil params)))
1491 (setq sql-prompt-regexp "^mysql>")
1492 (setq sql-prompt-length 6)
1493 (setq sql-buffer (current-buffer))
1494 (sql-interactive-mode)
1495 (message "Login...done")
1496 (pop-to-buffer sql-buffer)))
1497
1498 \f
1499
1500 ;;;###autoload
1501 (defun sql-solid ()
1502 "Run solsql by Solid as an inferior process.
1503
1504 If buffer `*SQL*' exists but no process is running, make a new process.
1505 If buffer exists and a process is running, just switch to buffer
1506 `*SQL*'.
1507
1508 Interpreter used comes from variable `sql-solid-program'. Login uses
1509 the variables `sql-user', `sql-password', and `sql-server' as
1510 defaults, if set.
1511
1512 The buffer is put in sql-interactive-mode, giving commands for sending
1513 input. See `sql-interactive-mode'.
1514
1515 To specify a coding system for converting non-ASCII characters
1516 in the input and output to the process, use \\[universal-coding-system-argument]
1517 before \\[sql-solid]. You can also specify this with \\[set-buffer-process-coding-system]
1518 in the SQL buffer, after you start the process.
1519 The default comes from `process-coding-system-alist' and
1520 `default-process-coding-system'.
1521
1522 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1523 (interactive)
1524 (if (comint-check-proc "*SQL*")
1525 (pop-to-buffer "*SQL*")
1526 (sql-get-login 'user 'password 'server)
1527 (message "Login...")
1528 ;; Put all parameters to the program (if defined) in a list and call
1529 ;; make-comint.
1530 (let ((params))
1531 ;; It only makes sense if both username and password are there.
1532 (if (not (or (string= "" sql-user)
1533 (string= "" sql-password)))
1534 (setq params (append (list sql-user sql-password) params)))
1535 (if (not (string= "" sql-server))
1536 (setq params (append (list sql-server) params)))
1537 (set-buffer (apply 'make-comint "SQL" sql-solid-program
1538 nil params)))
1539 (setq sql-prompt-regexp "^")
1540 (setq sql-prompt-length 0)
1541 (setq sql-buffer (current-buffer))
1542 (sql-interactive-mode)
1543 (message "Login...done")
1544 (pop-to-buffer sql-buffer)))
1545
1546 \f
1547
1548 ;;;###autoload
1549 (defun sql-ingres ()
1550 "Run sql by Ingres as an inferior process.
1551
1552 If buffer `*SQL*' exists but no process is running, make a new process.
1553 If buffer exists and a process is running, just switch to buffer
1554 `*SQL*'.
1555
1556 Interpreter used comes from variable `sql-ingres-program'. Login uses
1557 the variable `sql-database' as default, if set.
1558
1559 The buffer is put in sql-interactive-mode, giving commands for sending
1560 input. See `sql-interactive-mode'.
1561
1562 To specify a coding system for converting non-ASCII characters
1563 in the input and output to the process, use \\[universal-coding-system-argument]
1564 before \\[sql-ingres]. You can also specify this with \\[set-buffer-process-coding-system]
1565 in the SQL buffer, after you start the process.
1566 The default comes from `process-coding-system-alist' and
1567 `default-process-coding-system'.
1568
1569 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1570 (interactive)
1571 (if (comint-check-proc "*SQL*")
1572 (pop-to-buffer "*SQL*")
1573 (sql-get-login 'database)
1574 (message "Login...")
1575 ;; username and password are ignored.
1576 (if (string= "" sql-database)
1577 (set-buffer (make-comint "SQL" sql-ingres-program nil))
1578 (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database)))
1579 (setq sql-prompt-regexp "^\* ")
1580 (setq sql-prompt-length 2)
1581 (setq sql-buffer (current-buffer))
1582 (sql-interactive-mode)
1583 (message "Login...done")
1584 (pop-to-buffer sql-buffer)))
1585
1586 \f
1587
1588 ;;;###autoload
1589 (defun sql-ms ()
1590 "Run isql by Microsoft as an inferior process.
1591
1592 If buffer `*SQL*' exists but no process is running, make a new process.
1593 If buffer exists and a process is running, just switch to buffer
1594 `*SQL*'.
1595
1596 Interpreter used comes from variable `sql-ms-program'. Login uses the
1597 variables `sql-user', `sql-password', `sql-database', and `sql-server'
1598 as defaults, if set.
1599
1600 The buffer is put in sql-interactive-mode, giving commands for sending
1601 input. See `sql-interactive-mode'.
1602
1603 To specify a coding system for converting non-ASCII characters
1604 in the input and output to the process, use \\[universal-coding-system-argument]
1605 before \\[sql-ms]. You can also specify this with \\[set-buffer-process-coding-system]
1606 in the SQL buffer, after you start the process.
1607 The default comes from `process-coding-system-alist' and
1608 `default-process-coding-system'.
1609
1610 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1611 (interactive)
1612 (if (comint-check-proc "*SQL*")
1613 (pop-to-buffer "*SQL*")
1614 (sql-get-login 'user 'password 'database 'server)
1615 (message "Login...")
1616 ;; Put all parameters to the program (if defined) in a list and call
1617 ;; make-comint.
1618 (let ((params '("-w 300")))
1619 (if (not (string= "" sql-server))
1620 (setq params (append (list "-S" sql-server) params)))
1621 (if (not (string= "" sql-database))
1622 (setq params (append (list "-d" sql-database) params)))
1623 (if (not (string= "" sql-user))
1624 (setq params (append (list "-U" sql-user) params)))
1625 (if (not (string= "" sql-password))
1626 (setq params (append (list "-P" sql-password) params))
1627 ;; If -P is passed to ISQL as the last argument without a password,
1628 ;; it's considered null.
1629 (setq params (append params (list "-P"))))
1630 (set-buffer (apply 'make-comint "SQL" sql-ms-program
1631 nil params)))
1632 (setq sql-prompt-regexp "^[0-9]*>")
1633 (setq sql-prompt-length 5)
1634 (setq sql-buffer (current-buffer))
1635 (sql-interactive-mode)
1636 (message "Login...done")
1637 (pop-to-buffer sql-buffer)))
1638
1639 \f
1640
1641 ;;;###autoload
1642 (defun sql-postgres ()
1643 "Run psql by Postgres as an inferior process.
1644
1645 If buffer `*SQL*' exists but no process is running, make a new process.
1646 If buffer exists and a process is running, just switch to buffer
1647 `*SQL*'.
1648
1649 Interpreter used comes from variable `sql-postgres-program'. Login uses
1650 the variables `sql-database' and `sql-server' as default, if set.
1651 Additional command line parameters can be stored in the list
1652 `sql-postgres-options'.
1653
1654 The buffer is put in sql-interactive-mode, giving commands for sending
1655 input. See `sql-interactive-mode'.
1656
1657 To specify a coding system for converting non-ASCII characters
1658 in the input and output to the process, use \\[universal-coding-system-argument]
1659 before \\[sql-postgres]. You can also specify this with \\[set-buffer-process-coding-system]
1660 in the SQL buffer, after you start the process.
1661 The default comes from `process-coding-system-alist' and
1662 `default-process-coding-system'. If your output lines end with ^M,
1663 your might try undecided-dos as a coding system. If this doesn't help,
1664 Try to set `comint-output-filter-functions' like this:
1665
1666 \(setq comint-output-filter-functions (append comint-output-filter-functions
1667 '(comint-strip-ctrl-m)))
1668
1669 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1670 (interactive)
1671 (if (comint-check-proc "*SQL*")
1672 (pop-to-buffer "*SQL*")
1673 (sql-get-login 'database 'server)
1674 (message "Login...")
1675 ;; username and password are ignored. Jason Beegan suggest using
1676 ;; --pset and pager=off instead of \\o|cat. The later was the
1677 ;; solution by Gregor Zych. Jason's suggestion is the default value
1678 ;; for sql-postgres-options.
1679 (let ((params sql-postgres-options))
1680 (if (not (string= "" sql-database))
1681 (setq params (append (list sql-database) params)))
1682 (if (not (string= "" sql-server))
1683 (setq params (append (list "-h" sql-server) params)))
1684 (set-buffer (apply 'make-comint "SQL" sql-postgres-program
1685 nil params)))
1686 (setq sql-prompt-regexp "^.*> *")
1687 (setq sql-prompt-length 5)
1688 ;; This is a lousy hack to prevent psql from truncating it's output
1689 ;; and giving stupid warnings. If s.o. knows a way to prevent psql
1690 ;; from acting this way, then I would be very thankful to
1691 ;; incorporate this (Gregor Zych <zych@pool.informatik.rwth-aachen.de>)
1692 ;; (comint-send-string "*SQL*" "\\o \| cat\n")
1693 (setq sql-mode-font-lock-keywords sql-mode-postgres-font-lock-keywords)
1694 (setq sql-buffer (current-buffer))
1695 (sql-interactive-mode)
1696 (message "Login...done")
1697 (pop-to-buffer sql-buffer)))
1698
1699 \f
1700
1701 ;;;###autoload
1702 (defun sql-interbase ()
1703 "Run isql by Interbase as an inferior process.
1704
1705 If buffer `*SQL*' exists but no process is running, make a new process.
1706 If buffer exists and a process is running, just switch to buffer
1707 `*SQL*'.
1708
1709 Interpreter used comes from variable `sql-interbase-program'. Login
1710 uses the variables `sql-user', `sql-password', and `sql-database' as
1711 defaults, if set.
1712
1713 The buffer is put in sql-interactive-mode, giving commands for sending
1714 input. See `sql-interactive-mode'.
1715
1716 To specify a coding system for converting non-ASCII characters
1717 in the input and output to the process, use \\[universal-coding-system-argument]
1718 before \\[sql-interbase]. You can also specify this with \\[set-buffer-process-coding-system]
1719 in the SQL buffer, after you start the process.
1720 The default comes from `process-coding-system-alist' and
1721 `default-process-coding-system'.
1722
1723 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1724 (interactive)
1725 (if (comint-check-proc "*SQL*")
1726 (pop-to-buffer "*SQL*")
1727 (sql-get-login 'user 'password 'database)
1728 (message "Login...")
1729 ;; Put all parameters to the program (if defined) in a list and call
1730 ;; make-comint.
1731 (let ((params sql-interbase-options))
1732 (if (not (string= "" sql-user))
1733 (setq params (append (list "-u" sql-user) params)))
1734 (if (not (string= "" sql-password))
1735 (setq params (append (list "-p" sql-password) params)))
1736 (if (not (string= "" sql-database))
1737 (setq params (cons sql-database params))); add to the front!
1738 (set-buffer (apply 'make-comint "SQL" sql-interbase-program
1739 nil params)))
1740 (setq sql-prompt-regexp "^SQL> ")
1741 (setq sql-prompt-length 5)
1742 (setq sql-buffer (current-buffer))
1743 (sql-interactive-mode)
1744 (message "Login...done")
1745 (pop-to-buffer sql-buffer)))
1746
1747 \f
1748
1749 ;;;###autoload
1750 (defun sql-db2 ()
1751 "Run db2 by IBM as an inferior process.
1752
1753 If buffer `*SQL*' exists but no process is running, make a new process.
1754 If buffer exists and a process is running, just switch to buffer
1755 `*SQL*'.
1756
1757 Interpreter used comes from variable `sql-db2-program'. There is not
1758 automatic login.
1759
1760 The buffer is put in sql-interactive-mode, giving commands for sending
1761 input. See `sql-interactive-mode'.
1762
1763 If you use \\[sql-accumulate-and-indent] to send multiline commands to db2,
1764 newlines will be escaped if necessary. If you don't want that, use
1765
1766 set `comint-input-sender' back to `comint-simple-send'.
1767 comint-input-sender's value is
1768 comint-simple-send
1769
1770
1771 To specify a coding system for converting non-ASCII characters
1772 in the input and output to the process, use \\[universal-coding-system-argument]
1773 before \\[sql-db2]. You can also specify this with \\[set-buffer-process-coding-system]
1774 in the SQL buffer, after you start the process.
1775 The default comes from `process-coding-system-alist' and
1776 `default-process-coding-system'.
1777
1778 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1779 (interactive)
1780 (if (comint-check-proc "*SQL*")
1781 (pop-to-buffer "*SQL*")
1782 (message "Login...")
1783 ;; Put all parameters to the program (if defined) in a list and call
1784 ;; make-comint.
1785 (set-buffer (apply 'make-comint "SQL" sql-db2-program
1786 nil sql-db2-options))
1787 (setq sql-prompt-regexp "^db2 => ")
1788 (setq sql-prompt-length 7)
1789 (setq sql-buffer (current-buffer))
1790 (sql-interactive-mode)
1791 ;; Escape newlines. This must come after sql-interactive-mode
1792 ;; because all local variables will be killed, there.
1793 (setq comint-input-sender 'sql-escape-newlines-and-send)
1794 (message "Login...done")
1795 (pop-to-buffer sql-buffer)))
1796
1797 (provide 'sql)
1798
1799 ;;; sql.el ends here