(all): Make `indicate-buffer-boundaries' display values set outside
[bpt/emacs.git] / lisp / progmodes / sql.el
CommitLineData
95e4b2ef
RS
1;;; sql.el --- specialized comint.el for SQL interpreters
2
034babe1
NR
3;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4;; Free Software Foundation, Inc.
95e4b2ef 5
1533eb58 6;; Author: Alex Schroeder <alex@gnu.org>
dc45d1a6 7;; Maintainer: Michael Mauger <mmaug@yahoo.com>
9a9069c9 8;; Version: 2.0.1
dab100d7 9;; Keywords: comm languages processes
9fd8cb36 10;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el
aa88e662 11;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode
95e4b2ef
RS
12
13;; This file is part of GNU Emacs.
14
15;; GNU Emacs is free software; you can redistribute it and/or modify
16;; it under the terms of the GNU General Public License as published by
17;; the Free Software Foundation; either version 2, or (at your option)
18;; any later version.
19
20;; GNU Emacs is distributed in the hope that it will be useful,
21;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23;; GNU General Public License for more details.
24
25;; You should have received a copy of the GNU General Public License
26;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
27;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28;; Boston, MA 02110-1301, USA.
95e4b2ef
RS
29
30;;; Commentary:
31
c04bb32e 32;; Please send bug reports and bug fixes to the mailing list at
801d1cb0
AS
33;; sql.el@gnu.org. If you want to subscribe to the mailing list, send
34;; mail to sql.el-request@gnu.org with `subscribe sql.el FIRSTNAME
1533eb58 35;; LASTNAME' in the mail body.
95e4b2ef 36
95e4b2ef
RS
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
801d1cb0 42;; maintain and little or no bells and whistles.
95e4b2ef
RS
43
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.
48
49;; sql-interactive-mode is used to interact with a SQL interpreter
dab100d7
RS
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.
95e4b2ef
RS
53
54;; The list of currently supported interpreters and the corresponding
dab100d7 55;; entry function used to create the SQLi buffers is shown with
95e4b2ef
RS
56;; `sql-help' (M-x sql-help).
57
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
62;; use.
63
311e7a89
GM
64;; sql-mode can be used to keep editing SQL statements. The SQL
65;; statements can be sent to the SQL process in the SQLi buffer.
95e4b2ef
RS
66
67;; For documentation on the functionality provided by comint mode, and
eb3f61dd 68;; the hooks available for customizing it, see the file `comint.el'.
95e4b2ef 69
801d1cb0
AS
70;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and
71;; `imenu-add-menubar-index'.
95e4b2ef
RS
72
73;;; Requirements for Emacs 19.34:
74
75;; If you are using Emacs 19.34, you will have to get and install
76;; the file regexp-opt.el
77;; <URL:ftp://ftp.ifi.uio.no/pub/emacs/emacs-20.3/lisp/emacs-lisp/regexp-opt.el>
78;; and the custom package
79;; <URL:http://www.dina.kvl.dk/~abraham/custom/>.
80
81;;; Bugs:
82
78024f88
AS
83;; sql-ms now uses osql instead of isql. Osql flushes its error
84;; stream more frequently than isql so that error messages are
85;; available. There is no prompt and some output still is buffered.
86;; This improves the interaction under Emacs but it still is somewhat
87;; awkward.
88
89;; Quoted identifiers are not supported for hilighting. Most
90;; databases support the use of double quoted strings in place of
91;; identifiers; ms (Microsoft SQLServer) also supports identifiers
92;; enclosed within brackets [].
95e4b2ef 93
9c7bda2f 94;; ChangeLog available on request.
95e4b2ef 95
78024f88
AS
96;;; Product Support:
97
98;; To add support for additional SQL products the following steps
99;; must be followed ("xyz" is the name of the product in the examples
100;; below):
101
102;; 1) Add the product to `sql-product' choice list.
103
104;; (const :tag "XyzDB" xyz)
105
9fd8cb36 106;; 2) Add an entry to the `sql-product-alist' list.
78024f88
AS
107
108;; (xyz
109;; :font-lock sql-mode-xyz-font-lock-keywords
110;; :sqli-login (user password server database)
111;; :sqli-connect sql-connect-xyz
112;; :sqli-prompt-regexp "^xyzdb> "
113;; :sqli-prompt-length 7
114;; :sqli-input-sender nil
115;; :syntax-alist ((?# . "w")))
116
117;; 3) Add customizable values for the product interpreter and options.
118
119;; ;; Customization for XyzDB
120;;
121;; (defcustom sql-xyz-program "ixyz"
122;; "*Command to start ixyz by XyzDB."
123;; :type 'file
124;; :group 'SQL)
125;;
126;; (defcustom sql-xyz-options '("-X" "-Y" "-Z")
127;; "*List of additional options for `sql-xyz-program'."
128;; :type '(repeat string)
129;; :group 'SQL)
130
131;; 4) Add an entry to SQL->Product submenu.
132
133;; ["XyzDB" sql-highlight-xyz-keywords
134;; :style radio
135;; :selected (eq sql-product 'xyz)]
136
137;; 5) Add the font-lock specifications. At a minimum, default to
138;; using ANSI keywords. See sql-mode-oracle-font-lock-keywords for
139;; a more complex example.
140
9fd8cb36 141;; (defvar sql-mode-xyz-font-lock-keywords nil
78024f88
AS
142;; "XyzDB SQL keywords used by font-lock.")
143
144;; 6) Add a product highlighting function.
145
146;; (defun sql-highlight-xyz-keywords ()
147;; "Highlight XyzDB keywords."
148;; (interactive)
149;; (sql-set-product 'xyz))
150
151;; 7) Add an autoloaded SQLi function.
152
153;; ;;;###autoload
154;; (defun sql-xyz ()
155;; "Run ixyz by XyzDB as an inferior process."
156;; (interactive)
157;; (sql-product-interactive 'xyz))
158
159;; 8) Add a connect function which formats the command line arguments
160;; and starts the product interpreter in a comint buffer. See the
161;; existing connect functions for examples of the types of
162;; processing available.
163
164;; (defun sql-connect-xyz ()
165;; "Create comint buffer and connect to XyzDB using the login
166;; parameters and command options."
167;;
168;; ;; Do something with `sql-user', `sql-password',
169;; ;; `sql-database', and `sql-server'.
170;; (let ((params sql-xyz-options))
171;; (if (not (string= "" sql-server))
172;; (setq params (append (list "-S" sql-server) params)))
173;; (if (not (string= "" sql-database))
174;; (setq params (append (list "-D" sql-database) params)))
175;; (if (not (string= "" sql-password))
176;; (setq params (append (list "-P" sql-password) params)))
177;; (if (not (string= "" sql-user))
178;; (setq params (append (list "-U" sql-user) params)))
179;; (set-buffer (apply 'make-comint "SQL" sql-xyz-program
180;; nil params))))
181
182;; 9) Save and compile sql.el.
183
b4dd5c9c
JB
184;;; To Do:
185
186;; Add better hilight support for other brands; there is a bias towards
187;; Oracle because that's what I use at work. Anybody else just send in
188;; your lists of reserved words, keywords and builtin functions! As
189;; long as I don't receive any feedback, everything is hilighted with
190;; ANSI keywords only. I received the list of ANSI keywords from a
191;; user; if you know of any changes, let me know.
192
193;; Add different hilighting levels.
95e4b2ef
RS
194
195;;; Thanks to all the people who helped me out:
196
9fd8cb36 197;; Alex Schroeder <alex@gnu.org>
95e4b2ef
RS
198;; Kai Blauberg <kai.blauberg@metla.fi>
199;; <ibalaban@dalet.com>
200;; Yair Friedman <yfriedma@JohnBryce.Co.Il>
201;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
a081a529 202;; nino <nino@inform.dk>
801d1cb0 203;; Berend de Boer <berend@pobox.com>
9fd8cb36 204;; Adam Jenkins <adam@thejenkins.org>
9a9069c9
SM
205;; Michael Mauger <mmaug@yahoo.com> -- improved product support
206;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support
207;; Harald Maier <maierh@myself.com> -- sql-send-string
208;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections
dab100d7 209
95e4b2ef
RS
210\f
211
212;;; Code:
213
214(require 'comint)
215;; Need the following to allow GNU Emacs 19 to compile the file.
78024f88
AS
216(eval-when-compile
217 (require 'regexp-opt))
95e4b2ef 218(require 'custom)
9fd8cb36
SM
219(eval-when-compile ;; needed in Emacs 19, 20
220 (setq max-specpdl-size 2000))
95e4b2ef
RS
221
222;;; Allow customization
223
224(defgroup SQL nil
b9584f65 225 "Running a SQL interpreter from within Emacs buffers."
6629e5ba 226 :version "20.4"
95e4b2ef
RS
227 :group 'processes)
228
78024f88 229;; These four variables will be used as defaults, if set.
95e4b2ef
RS
230
231(defcustom sql-user ""
232 "*Default username."
233 :type 'string
234 :group 'SQL)
235
236(defcustom sql-password ""
237 "*Default password.
238
239Storing your password in a textfile such as ~/.emacs could be dangerous.
240Customizing your password will store it in your ~/.emacs file."
241 :type 'string
242 :group 'SQL)
243
244(defcustom sql-database ""
245 "*Default database."
246 :type 'string
247 :group 'SQL)
248
249(defcustom sql-server ""
dab100d7 250 "*Default server or host."
95e4b2ef
RS
251 :type 'string
252 :group 'SQL)
253
78024f88
AS
254;; SQL Product support
255(defcustom sql-product 'ansi
256 "*Select the SQL database product used so that buffers can be
257highlighted properly when you open them."
258 :type '(choice (const :tag "ANSI" ansi)
259 (const :tag "DB2" db2)
260 (const :tag "Informix" informix)
261 (const :tag "Ingres" ingres)
262 (const :tag "Interbase" interbase)
263 (const :tag "Linter" linter)
264 (const :tag "Microsoft" ms)
265 (const :tag "MySQL" mysql)
266 (const :tag "Oracle" oracle)
267 (const :tag "PostGres" postgres)
268 (const :tag "Solid" solid)
269 (const :tag "SQLite" sqlite)
270 (const :tag "Sybase" sybase))
271 :group 'SQL)
272
273(defvar sql-interactive-product nil
274 "Product under `sql-interactive-mode'.")
275
9fd8cb36 276(defvar sql-product-alist
78024f88
AS
277 '((ansi
278 :font-lock sql-mode-ansi-font-lock-keywords)
279 (db2
280 :font-lock sql-mode-db2-font-lock-keywords
281 :sqli-login nil
282 :sqli-connect sql-connect-db2
283 :sqli-prompt-regexp "^db2 => "
284 :sqli-prompt-length 7)
285 (informix
286 :font-lock sql-mode-informix-font-lock-keywords
287 :sqli-login (database)
288 :sqli-connect sql-connect-informix
289 :sqli-prompt-regexp "^SQL> "
290 :sqli-prompt-length 5)
291 (ingres
292 :font-lock sql-mode-ingres-font-lock-keywords
293 :sqli-login (database)
294 :sqli-connect sql-connect-ingres
295 :sqli-prompt-regexp "^\* "
296 :sqli-prompt-length 2)
297 (interbase
298 :font-lock sql-mode-interbase-font-lock-keywords
299 :sqli-login (user password database)
300 :sqli-connect sql-connect-interbase
301 :sqli-prompt-regexp "^SQL> "
302 :sqli-prompt-length 5)
303 (linter
304 :font-lock sql-mode-linter-font-lock-keywords
305 :sqli-login (user password database server)
306 :sqli-connect sql-connect-linter
307 :sqli-prompt-regexp "^SQL>"
308 :sqli-prompt-length 4)
309 (ms
310 :font-lock sql-mode-ms-font-lock-keywords
311 :sqli-login (user password server database)
312 :sqli-connect sql-connect-ms
313 :sqli-prompt-regexp "^[0-9]*>"
314 :sqli-prompt-length 5
315 :syntax-alist ((?@ . "w")))
316 (mysql
317 :font-lock sql-mode-mysql-font-lock-keywords
318 :sqli-login (user password database server)
319 :sqli-connect sql-connect-mysql
320 :sqli-prompt-regexp "^mysql> "
321 :sqli-prompt-length 6)
322 (oracle
323 :font-lock sql-mode-oracle-font-lock-keywords
324 :sqli-login (user password database)
325 :sqli-connect sql-connect-oracle
326 :sqli-prompt-regexp "^SQL> "
327 :sqli-prompt-length 5
328 :syntax-alist ((?$ . "w") (?# . "w")))
329 (postgres
330 :font-lock sql-mode-postgres-font-lock-keywords
9fd8cb36 331 :sqli-login (user database server)
78024f88 332 :sqli-connect sql-connect-postgres
9fd8cb36 333 :sqli-prompt-regexp "^.*[#>] *"
78024f88
AS
334 :sqli-prompt-length 5)
335 (solid
336 :font-lock sql-mode-solid-font-lock-keywords
337 :sqli-login (user password server)
338 :sqli-connect sql-connect-solid
339 :sqli-prompt-regexp "^"
340 :sqli-prompt-length 0)
341 (sqlite
342 :font-lock sql-mode-sqlite-font-lock-keywords
343 :sqli-login (user password server database)
344 :sqli-connect sql-connect-sqlite
345 :sqli-prompt-regexp "^sqlite> "
346 :sqli-prompt-length 8)
347 (sybase
348 :font-lock sql-mode-sybase-font-lock-keywords
349 :sqli-login (server user password database)
350 :sqli-connect sql-connect-sybase
351 :sqli-prompt-regexp "^SQL> "
352 :sqli-prompt-length 5
353 :syntax-alist ((?@ . "w")))
354 )
355 "This variable contains a list of product features for each of the
356SQL products handled by `sql-mode'. Without an entry in this list a
357product will not be properly highlighted and will not support
358`sql-interactive-mode'.
359
360Each element in the list is in the following format:
361
362 \(PRODUCT FEATURE VALUE ...)
363
364where PRODUCT is the appropriate value of `sql-product'. The product
365name is then followed by FEATURE-VALUE pairs. If a FEATURE is not
366specified, its VALUE is treated as nil. FEATURE must be one of the
367following:
368
369 :font-lock name of the variable containing the product
370 specific font lock highlighting patterns.
371
372 :sqli-login a list of login parameters (i.e., user,
373 password, database and server) needed to
374 connect to the database.
375
376 :sqli-connect the name of a function which accepts no
377 parameters that will use the values of
378 `sql-user', `sql-password',
379 `sql-database' and `sql-server' to open a
380 comint buffer and connect to the
381 database. Do product specific
382 configuration of comint in this function.
383
9fd8cb36
SM
384 :sqli-prompt-regexp a regular expression string that matches
385 the prompt issued by the product
386 interpreter. (Not needed in 21.3+)
78024f88 387
9fd8cb36
SM
388 :sqli-prompt-length the length of the prompt on the line.(Not
389 needed in 21.3+)
78024f88
AS
390
391 :syntax-alist an alist of syntax table entries to enable
392 special character treatment by font-lock and
393 imenu. ")
394
801d1cb0
AS
395;; misc customization of sql.el behaviour
396
9ef3882f
GM
397(defcustom sql-electric-stuff nil
398 "Treat some input as electric.
399If set to the symbol `semicolon', then hitting `;' will send current
400input in the SQLi buffer to the process.
401If set to the symbol `go', then hitting `go' on a line by itself will
402send current input in the SQLi buffer to the process.
403If set to nil, then you must use \\[comint-send-input] in order to send
404current input in the SQLi buffer to the process."
405 :type '(choice (const :tag "Nothing" nil)
406 (const :tag "The semikolon `;'" semicolon)
407 (const :tag "The string `go' by itself" go))
408 :version "20.8"
409 :group 'SQL)
410
95e4b2ef
RS
411(defcustom sql-pop-to-buffer-after-send-region nil
412 "*If t, pop to the buffer SQL statements are sent to.
413
414After a call to `sql-send-region' or `sql-send-buffer',
415the window is split and the SQLi buffer is shown. If this
a081a529
RS
416variable is not nil, that buffer's window will be selected
417by calling `pop-to-buffer'. If this variable is nil, that
418buffer is shown using `display-buffer'."
c7055d66
RS
419 :type 'boolean
420 :group 'SQL)
421
801d1cb0
AS
422;; imenu support for sql-mode.
423
424(defvar sql-imenu-generic-expression
78024f88 425 ;; Items are in reverse order because they are rendered in reverse.
9fd8cb36
SM
426 '(("Rules/Defaults" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(rule\\|default\\)\\s-+\\(\\w+\\)" 3)
427 ("Sequences" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*sequence\\s-+\\(\\w+\\)" 2)
428 ("Triggers" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*trigger\\s-+\\(\\w+\\)" 2)
429 ("Functions" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?function\\s-+\\(\\w+\\)" 3)
430 ("Procedures" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4)
431 ("Packages" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3)
432 ("Indexes" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*index\\s-+\\(\\w+\\)" 2)
433 ("Tables/Views" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(table\\|view\\)\\s-+\\(\\w+\\)" 3))
801d1cb0
AS
434 "Define interesting points in the SQL buffer for `imenu'.
435
9ef3882f
GM
436This is used to set `imenu-generic-expression' when SQL mode is
437entered. Subsequent changes to sql-imenu-generic-expression will not
438affect existing SQL buffers because imenu-generic-expression is a
439local variable.")
801d1cb0
AS
440
441;; history file
442
c7055d66
RS
443(defcustom sql-input-ring-file-name nil
444 "*If non-nil, name of the file to read/write input history.
445
9ef73b91
KH
446You have to set this variable if you want the history of your commands
447saved from one Emacs session to the next. If this variable is set,
448exiting the SQL interpreter in an SQLi buffer will write the input
449history to the specified file. Starting a new process in a SQLi buffer
450will read the input history from the specified file.
451
77d352a6
GM
452This is used to initialize `comint-input-ring-file-name'.
453
454Note that the size of the input history is determined by the variable
455`comint-input-ring-size'."
c7055d66
RS
456 :type '(choice (const :tag "none" nil)
457 (file))
458 :group 'SQL)
459
460(defcustom sql-input-ring-separator "\n--\n"
461 "*Separator between commands in the history file.
462
463If set to \"\\n\", each line in the history file will be interpreted as
464one command. Multi-line commands are split into several commands when
465the input ring is initialized from a history file.
466
77d352a6
GM
467This variable used to initialize `comint-input-ring-separator'.
468`comint-input-ring-separator' is part of Emacs 21; if your Emacs
469does not have it, setting `sql-input-ring-separator' will have no
470effect. In that case multiline commands will be split into several
471commands when the input history is read, as if you had set
472`sql-input-ring-separator' to \"\\n\"."
95e4b2ef
RS
473 :type 'string
474 :group 'SQL)
475
476;; The usual hooks
477
478(defcustom sql-interactive-mode-hook '()
eb3f61dd 479 "*Hook for customizing `sql-interactive-mode'."
95e4b2ef
RS
480 :type 'hook
481 :group 'SQL)
482
483(defcustom sql-mode-hook '()
eb3f61dd 484 "*Hook for customizing `sql-mode'."
95e4b2ef
RS
485 :type 'hook
486 :group 'SQL)
487
c7055d66
RS
488(defcustom sql-set-sqli-hook '()
489 "*Hook for reacting to changes of `sql-buffer'.
490
491This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
492is changed."
493 :type 'hook
494 :group 'SQL)
495
eb3f61dd 496;; Customization for Oracle
95e4b2ef
RS
497
498(defcustom sql-oracle-program "sqlplus"
499 "*Command to start sqlplus by Oracle.
500
501Starts `sql-interactive-mode' after doing some setup.
502
503Under NT, \"sqlplus\" usually starts the sqlplus \"GUI\". In order to
504start the sqlplus console, use \"plus33\" or something similar. You
505will find the file in your Orant\\bin directory.
506
a081a529
RS
507The program can also specify a TCP connection. See `make-comint'."
508 :type 'file
509 :group 'SQL)
510
9ef3882f
GM
511(defcustom sql-oracle-options nil
512 "*List of additional options for `sql-oracle-program'."
513 :type '(repeat string)
514 :version "20.8"
515 :group 'SQL)
516
5d538ce3
JB
517;; Customization for SQLite
518
519(defcustom sql-sqlite-program "sqlite"
520 "*Command to start SQLite.
521
522Starts `sql-interactive-mode' after doing some setup.
523
524The program can also specify a TCP connection. See `make-comint'."
525 :type 'file
526 :group 'SQL)
527
528(defcustom sql-sqlite-options nil
78024f88 529 "*List of additional options for `sql-sqlite-program'.
5d538ce3
JB
530The following list of options is reported to make things work
531on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
532 :type '(repeat string)
533 :version "20.8"
534 :group 'SQL)
535
eb3f61dd 536;; Customization for MySql
a081a529
RS
537
538(defcustom sql-mysql-program "mysql"
539 "*Command to start mysql by TcX.
540
541Starts `sql-interactive-mode' after doing some setup.
542
dab100d7
RS
543The program can also specify a TCP connection. See `make-comint'."
544 :type 'file
545 :group 'SQL)
546
542c6552 547(defcustom sql-mysql-options nil
524c8caf
GM
548 "*List of additional options for `sql-mysql-program'.
549The following list of options is reported to make things work
550on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
542c6552
GM
551 :type '(repeat string)
552 :version "20.8"
553 :group 'SQL)
554
eb3f61dd 555;; Customization for Solid
dab100d7
RS
556
557(defcustom sql-solid-program "solsql"
558 "*Command to start SOLID SQL Editor.
559
560Starts `sql-interactive-mode' after doing some setup.
561
95e4b2ef
RS
562The program can also specify a TCP connection. See `make-comint'."
563 :type 'file
564 :group 'SQL)
565
eb3f61dd 566;; Customization for SyBase
95e4b2ef
RS
567
568(defcustom sql-sybase-program "isql"
801d1cb0 569 "*Command to start isql by SyBase.
95e4b2ef
RS
570
571Starts `sql-interactive-mode' after doing some setup.
572
573The program can also specify a TCP connection. See `make-comint'."
574 :type 'file
575 :group 'SQL)
576
9b5360aa
GM
577(defcustom sql-sybase-options nil
578 "*List of additional options for `sql-sybase-program'.
579Some versions of isql might require the -n option in order to work."
580 :type '(repeat string)
581 :version "20.8"
582 :group 'SQL)
583
eb3f61dd 584;; Customization for Informix
95e4b2ef
RS
585
586(defcustom sql-informix-program "dbaccess"
801d1cb0 587 "*Command to start dbaccess by Informix.
95e4b2ef
RS
588
589Starts `sql-interactive-mode' after doing some setup.
590
591The program can also specify a TCP connection. See `make-comint'."
592 :type 'file
593 :group 'SQL)
594
eb3f61dd 595;; Customization for Ingres
95e4b2ef
RS
596
597(defcustom sql-ingres-program "sql"
801d1cb0 598 "*Command to start sql by Ingres.
95e4b2ef
RS
599
600Starts `sql-interactive-mode' after doing some setup.
601
602The program can also specify a TCP connection. See `make-comint'."
603 :type 'file
604 :group 'SQL)
605
eb3f61dd 606;; Customization for Microsoft
95e4b2ef 607
78024f88
AS
608(defcustom sql-ms-program "osql"
609 "*Command to start osql by Microsoft.
95e4b2ef
RS
610
611Starts `sql-interactive-mode' after doing some setup.
612
613The program can also specify a TCP connection. See `make-comint'."
614 :type 'file
615 :group 'SQL)
616
f4df536d
JB
617(defcustom sql-ms-options '("-w" "300" "-n")
618 ;; -w is the linesize
619 "*List of additional options for `sql-ms-program'."
620 :type '(repeat string)
bf247b6e 621 :version "22.1"
f4df536d
JB
622 :group 'SQL)
623
eb3f61dd 624;; Customization for Postgres
95e4b2ef
RS
625
626(defcustom sql-postgres-program "psql"
801d1cb0 627 "Command to start psql by Postgres.
95e4b2ef
RS
628
629Starts `sql-interactive-mode' after doing some setup.
630
631The program can also specify a TCP connection. See `make-comint'."
632 :type 'file
633 :group 'SQL)
634
524c8caf 635(defcustom sql-postgres-options '("-P" "pager=off")
311e7a89 636 "*List of additional options for `sql-postgres-program'.
aa88e662
GM
637The default setting includes the -P option which breaks older versions
638of the psql client (such as version 6.5.3). The -P option is equivalent
639to the --pset option. If you want the psql to prompt you for a user
640name, add the string \"-u\" to the list of options. If you want to
641provide a user name on the command line (newer versions such as 7.1),
642add your name with a \"-U\" prefix (such as \"-Umark\") to the list."
311e7a89
GM
643 :type '(repeat string)
644 :version "20.8"
645 :group 'SQL)
646
eb3f61dd
GM
647;; Customization for Interbase
648
649(defcustom sql-interbase-program "isql"
650 "*Command to start isql by Interbase.
651
652Starts `sql-interactive-mode' after doing some setup.
653
654The program can also specify a TCP connection. See `make-comint'."
655 :type 'file
656 :group 'SQL)
657
658(defcustom sql-interbase-options nil
659 "*List of additional options for `sql-interbase-program'."
660 :type '(repeat string)
661 :version "20.8"
662 :group 'SQL)
663
624ef9b3
GM
664;; Customization for DB2
665
666(defcustom sql-db2-program "db2"
667 "*Command to start db2 by IBM.
668
669Starts `sql-interactive-mode' after doing some setup.
670
671The program can also specify a TCP connection. See `make-comint'."
672 :type 'file
673 :group 'SQL)
674
675(defcustom sql-db2-options nil
676 "*List of additional options for `sql-db2-program'."
677 :type '(repeat string)
678 :version "20.8"
679 :group 'SQL)
680
f4df536d
JB
681;; Customization for Linter
682
683(defcustom sql-linter-program "inl"
684 "*Command to start inl by RELEX.
685
686Starts `sql-interactive-mode' after doing some setup."
687 :type 'file
688 :group 'SQL)
689
690(defcustom sql-linter-options nil
691 "*List of additional options for `sql-linter-program'."
692 :type '(repeat string)
693 :version "21.3"
694 :group 'SQL)
695
95e4b2ef
RS
696\f
697
698;;; Variables which do not need customization
699
700(defvar sql-user-history nil
701 "History of usernames used.")
702
703(defvar sql-database-history nil
704 "History of databases used.")
705
706(defvar sql-server-history nil
707 "History of servers used.")
708
709;; Passwords are not kept in a history.
710
711(defvar sql-buffer nil
dab100d7
RS
712 "Current SQLi buffer.
713
714The global value of sql-buffer is the name of the latest SQLi buffer
715created. Any SQL buffer created will make a local copy of this value.
716See `sql-interactive-mode' for more on multiple sessions. If you want
717to change the SQLi buffer a SQL mode sends its SQL strings to, change
c7055d66 718the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
95e4b2ef
RS
719
720(defvar sql-prompt-regexp nil
721 "Prompt used to initialize `comint-prompt-regexp'.
722
78024f88 723You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.")
95e4b2ef 724
a081a529
RS
725(defvar sql-prompt-length 0
726 "Prompt used to set `left-margin' in `sql-interactive-mode'.
727
78024f88 728You can change `sql-prompt-length' on `sql-interactive-mode-hook'.")
a081a529 729
c7055d66
RS
730(defvar sql-alternate-buffer-name nil
731 "Buffer-local string used to possibly rename the SQLi buffer.
732
733Used by `sql-rename-buffer'.")
734
9ef3882f
GM
735;; Keymap for sql-interactive-mode.
736
f4df536d 737(defvar sql-interactive-mode-map
9ef3882f
GM
738 (let ((map (make-sparse-keymap)))
739 (if (functionp 'set-keymap-parent)
740 (set-keymap-parent map comint-mode-map); Emacs
741 (set-keymap-parents map (list comint-mode-map))); XEmacs
742 (if (functionp 'set-keymap-name)
743 (set-keymap-name map 'sql-interactive-mode-map)); XEmacs
744 (define-key map (kbd "C-j") 'sql-accumulate-and-indent)
745 (define-key map (kbd "C-c C-w") 'sql-copy-column)
746 (define-key map (kbd "O") 'sql-magic-go)
747 (define-key map (kbd "o") 'sql-magic-go)
748 (define-key map (kbd ";") 'sql-magic-semicolon)
749 map)
750 "Mode map used for `sql-interactive-mode'.
751Based on `comint-mode-map'.")
95e4b2ef
RS
752
753;; Keymap for sql-mode.
754
755(defvar sql-mode-map
756 (let ((map (make-sparse-keymap)))
9ef3882f
GM
757 (define-key map (kbd "C-c C-c") 'sql-send-paragraph)
758 (define-key map (kbd "C-c C-r") 'sql-send-region)
9fd8cb36 759 (define-key map (kbd "C-c C-s") 'sql-send-string)
9ef3882f 760 (define-key map (kbd "C-c C-b") 'sql-send-buffer)
95e4b2ef
RS
761 map)
762 "Mode map used for `sql-mode'.")
763
764;; easy menu for sql-mode.
765
801d1cb0
AS
766(easy-menu-define
767 sql-mode-menu sql-mode-map
95e4b2ef
RS
768 "Menu for `sql-mode'."
769 '("SQL"
dab100d7
RS
770 ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer)
771 (get-buffer-process sql-buffer))]
311e7a89
GM
772 ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs
773 mark-active)
78024f88 774 (mark t)); XEmacs
dab100d7
RS
775 (buffer-live-p sql-buffer)
776 (get-buffer-process sql-buffer))]
777 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)
778 (get-buffer-process sql-buffer))]
9fd8cb36 779 ["Send String" sql-send-string t]
78024f88
AS
780 ["--" nil nil]
781 ["Start SQLi session" sql-product-interactive (sql-product-feature :sqli-connect)]
dab100d7 782 ["Show SQLi buffer" sql-show-sqli-buffer t]
c7055d66 783 ["Set SQLi buffer" sql-set-sqli-buffer t]
801d1cb0 784 ["Pop to SQLi buffer after send"
95e4b2ef
RS
785 sql-toggle-pop-to-buffer-after-send-region
786 :style toggle
624ef9b3 787 :selected sql-pop-to-buffer-after-send-region]
78024f88
AS
788 ["--" nil nil]
789 ("Product"
790 ["ANSI" sql-highlight-ansi-keywords
791 :style radio
792 :selected (eq sql-product 'ansi)]
793 ["DB2" sql-highlight-db2-keywords
794 :style radio
795 :selected (eq sql-product 'db2)]
796 ["Informix" sql-highlight-informix-keywords
797 :style radio
798 :selected (eq sql-product 'informix)]
799 ["Ingres" sql-highlight-ingres-keywords
800 :style radio
801 :selected (eq sql-product 'ingres)]
802 ["Interbase" sql-highlight-interbase-keywords
803 :style radio
804 :selected (eq sql-product 'interbase)]
805 ["Linter" sql-highlight-linter-keywords
806 :style radio
807 :selected (eq sql-product 'linter)]
9fd8cb36 808 ["MS SQLServer" sql-highlight-ms-keywords
78024f88
AS
809 :style radio
810 :selected (eq sql-product 'ms)]
811 ["MySQL" sql-highlight-mysql-keywords
812 :style radio
813 :selected (eq sql-product 'mysql)]
814 ["Oracle" sql-highlight-oracle-keywords
815 :style radio
816 :selected (eq sql-product 'oracle)]
817 ["Postgres" sql-highlight-postgres-keywords
818 :style radio
819 :selected (eq sql-product 'postgres)]
820 ["Solid" sql-highlight-solid-keywords
821 :style radio
822 :selected (eq sql-product 'solid)]
823 ["SQLite" sql-highlight-sqlite-keywords
824 :style radio
825 :selected (eq sql-product 'sqlite)]
826 ["Sybase" sql-highlight-sybase-keywords
827 :style radio
828 :selected (eq sql-product 'sybase)]
f4df536d 829 )))
95e4b2ef 830
c7055d66
RS
831;; easy menu for sql-interactive-mode.
832
801d1cb0 833(easy-menu-define
c7055d66
RS
834 sql-interactive-mode-menu sql-interactive-mode-map
835 "Menu for `sql-interactive-mode'."
836 '("SQL"
837 ["Rename Buffer" sql-rename-buffer t]))
838
95e4b2ef
RS
839;; Abbreviations -- if you want more of them, define them in your
840;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too.
841
842(defvar sql-mode-abbrev-table nil
843 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")
9fd8cb36
SM
844(unless sql-mode-abbrev-table
845 (define-abbrev-table 'sql-mode-abbrev-table nil)
846 (mapcar
78024f88 847 ;; In Emacs 21.3+, provide SYSTEM-FLAG to define-abbrev.
9fd8cb36
SM
848 '(lambda (abbrev)
849 (let ((name (car abbrev))
850 (expansion (cdr abbrev)))
851 (condition-case nil
852 (define-abbrev sql-mode-abbrev-table name expansion nil 0 t)
853 (error
854 (define-abbrev sql-mode-abbrev-table name expansion)))))
855 '(("ins" "insert")
856 ("upd" "update")
857 ("del" "delete")
858 ("sel" "select")
859 ("proc" "procedure")
860 ("func" "function")
861 ("cr" "create"))))
95e4b2ef
RS
862
863;; Syntax Table
864
801d1cb0 865(defvar sql-mode-syntax-table
95e4b2ef
RS
866 (let ((table (make-syntax-table)))
867 ;; C-style comments /**/ (see elisp manual "Syntax Flags"))
868 (modify-syntax-entry ?/ ". 14" table)
869 (modify-syntax-entry ?* ". 23" table)
870 ;; double-dash starts comment
9a9069c9 871 (modify-syntax-entry ?- ". 12b" table)
95e4b2ef
RS
872 ;; newline and formfeed end coments
873 (modify-syntax-entry ?\n "> b" table)
874 (modify-syntax-entry ?\f "> b" table)
a081a529
RS
875 ;; single quotes (') quotes delimit strings
876 (modify-syntax-entry ?' "\"" table)
4da8ff79
RS
877 ;; backslash is no escape character
878 (modify-syntax-entry ?\\ "." table)
95e4b2ef
RS
879 table)
880 "Syntax table used in `sql-mode' and `sql-interactive-mode'.")
881
882;; Font lock support
883
78024f88 884(defvar sql-mode-font-lock-object-name
9fd8cb36
SM
885 (list (concat "^\\s-*\\(create\\|drop\\|alter\\)\\s-+" ;; lead off with CREATE, DROP or ALTER
886 "\\(\\w+\\s-+\\)*" ;; optional intervening keywords
887 "\\(table\\|view\\|package\\(\\s-+body\\)?\\|proc\\(edure\\)?"
888 "\\|function\\|trigger\\|sequence\\|rule\\|default\\)\\s-+"
889 "\\(\\w+\\)")
890 6 'font-lock-function-name-face)
891
892 "Pattern to match the names of top-level objects.
893
894The pattern matches the name in a CREATE, DROP or ALTER
895statement. The format of variable should be a valid
896`font-lock-keywords' entry.")
897
9fd8cb36
SM
898(defmacro sql-keywords-re (&rest keywords)
899 "Compile-time generation of regexp matching any one of KEYWORDS."
900 `(eval-when-compile
901 (concat "\\b"
902 (regexp-opt ',keywords t)
903 "\\b")))
78024f88
AS
904
905(defvar sql-mode-ansi-font-lock-keywords
9fd8cb36
SM
906 (let ((ansi-funcs (sql-keywords-re
907"abs" "avg" "bit_length" "cardinality" "cast" "char_length"
908"character_length" "coalesce" "convert" "count" "current_date"
909"current_path" "current_role" "current_time" "current_timestamp"
910"current_user" "extract" "localtime" "localtimestamp" "lower" "max"
911"min" "mod" "nullif" "octet_length" "overlay" "placing" "session_user"
912"substring" "sum" "system_user" "translate" "treat" "trim" "upper"
913"user"
914))
915
916 (ansi-non-reserved (sql-keywords-re
917"ada" "asensitive" "assignment" "asymmetric" "atomic" "between"
918"bitvar" "called" "catalog_name" "chain" "character_set_catalog"
919"character_set_name" "character_set_schema" "checked" "class_origin"
920"cobol" "collation_catalog" "collation_name" "collation_schema"
921"column_name" "command_function" "command_function_code" "committed"
922"condition_number" "connection_name" "constraint_catalog"
923"constraint_name" "constraint_schema" "contains" "cursor_name"
924"datetime_interval_code" "datetime_interval_precision" "defined"
925"definer" "dispatch" "dynamic_function" "dynamic_function_code"
926"existing" "exists" "final" "fortran" "generated" "granted"
927"hierarchy" "hold" "implementation" "infix" "insensitive" "instance"
928"instantiable" "invoker" "key_member" "key_type" "length" "m"
929"message_length" "message_octet_length" "message_text" "method" "more"
930"mumps" "name" "nullable" "number" "options" "overlaps" "overriding"
931"parameter_mode" "parameter_name" "parameter_ordinal_position"
932"parameter_specific_catalog" "parameter_specific_name"
933"parameter_specific_schema" "pascal" "pli" "position" "repeatable"
934"returned_length" "returned_octet_length" "returned_sqlstate"
935"routine_catalog" "routine_name" "routine_schema" "row_count" "scale"
936"schema_name" "security" "self" "sensitive" "serializable"
937"server_name" "similar" "simple" "source" "specific_name" "style"
938"subclass_origin" "sublist" "symmetric" "system" "table_name"
939"transaction_active" "transactions_committed"
940"transactions_rolled_back" "transform" "transforms" "trigger_catalog"
941"trigger_name" "trigger_schema" "type" "uncommitted" "unnamed"
942"user_defined_type_catalog" "user_defined_type_name"
943"user_defined_type_schema"
944))
945
946 (ansi-reserved (sql-keywords-re
947"absolute" "action" "add" "admin" "after" "aggregate" "alias" "all"
948"allocate" "alter" "and" "any" "are" "as" "asc" "assertion" "at"
949"authorization" "before" "begin" "both" "breadth" "by" "call"
950"cascade" "cascaded" "case" "catalog" "check" "class" "close"
951"collate" "collation" "column" "commit" "completion" "connect"
952"connection" "constraint" "constraints" "constructor" "continue"
953"corresponding" "create" "cross" "cube" "current" "cursor" "cycle"
954"data" "day" "deallocate" "declare" "default" "deferrable" "deferred"
955"delete" "depth" "deref" "desc" "describe" "descriptor" "destroy"
956"destructor" "deterministic" "diagnostics" "dictionary" "disconnect"
957"distinct" "domain" "drop" "dynamic" "each" "else" "end" "equals"
958"escape" "every" "except" "exception" "exec" "execute" "external"
959"false" "fetch" "first" "for" "foreign" "found" "free" "from" "full"
960"function" "general" "get" "global" "go" "goto" "grant" "group"
961"grouping" "having" "host" "hour" "identity" "ignore" "immediate" "in"
962"indicator" "initialize" "initially" "inner" "inout" "input" "insert"
963"intersect" "into" "is" "isolation" "iterate" "join" "key" "language"
964"last" "lateral" "leading" "left" "less" "level" "like" "limit"
965"local" "locator" "map" "match" "minute" "modifies" "modify" "module"
966"month" "names" "natural" "new" "next" "no" "none" "not" "null" "of"
967"off" "old" "on" "only" "open" "operation" "option" "or" "order"
968"ordinality" "out" "outer" "output" "pad" "parameter" "parameters"
969"partial" "path" "postfix" "prefix" "preorder" "prepare" "preserve"
970"primary" "prior" "privileges" "procedure" "public" "read" "reads"
971"recursive" "references" "referencing" "relative" "restrict" "result"
972"return" "returns" "revoke" "right" "role" "rollback" "rollup"
973"routine" "rows" "savepoint" "schema" "scroll" "search" "second"
974"section" "select" "sequence" "session" "set" "sets" "size" "some"
975"space" "specific" "specifictype" "sql" "sqlexception" "sqlstate"
976"sqlwarning" "start" "state" "statement" "static" "structure" "table"
977"temporary" "terminate" "than" "then" "timezone_hour"
978"timezone_minute" "to" "trailing" "transaction" "translation"
979"trigger" "true" "under" "union" "unique" "unknown" "unnest" "update"
980"usage" "using" "value" "values" "variable" "view" "when" "whenever"
981"where" "with" "without" "work" "write" "year"
982))
983
984 (ansi-types (sql-keywords-re
985"array" "binary" "bit" "blob" "boolean" "char" "character" "clob"
986"date" "dec" "decimal" "double" "float" "int" "integer" "interval"
987"large" "national" "nchar" "nclob" "numeric" "object" "precision"
988"real" "ref" "row" "scope" "smallint" "time" "timestamp" "varchar"
989"varying" "zone"
990)))
991
992 `((,ansi-non-reserved . font-lock-keyword-face)
993 (,ansi-reserved . font-lock-keyword-face)
9a9069c9 994 (,ansi-funcs . font-lock-builtin-face)
9fd8cb36 995 (,ansi-types . font-lock-type-face)))
95e4b2ef 996
78024f88 997 "ANSI SQL keywords used by font-lock.
95e4b2ef
RS
998
999This variable is used by `sql-mode' and `sql-interactive-mode'. The
1000regular expressions are created during compilation by calling the
1001function `regexp-opt'. Therefore, take a look at the source before
78024f88
AS
1002you define your own sql-mode-ansi-font-lock-keywords. You may want to
1003add functions and PL/SQL keywords.")
1004
1005(defvar sql-mode-oracle-font-lock-keywords
9fd8cb36
SM
1006 (let ((oracle-functions (sql-keywords-re
1007"abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2"
1008"avg" "bfilename" "bin_to_num" "bitand" "cast" "ceil" "chartorowid"
1009"chr" "coalesce" "compose" "concat" "convert" "corr" "cos" "cosh"
1010"count" "covar_pop" "covar_samp" "cume_dist" "current_date"
1011"current_timestamp" "current_user" "dbtimezone" "decode" "decompose"
1012"dense_rank" "depth" "deref" "dump" "empty_clob" "existsnode" "exp"
1013"extract" "extractvalue" "first" "first_value" "floor" "following"
1014"from_tz" "greatest" "group_id" "grouping_id" "hextoraw" "initcap"
1015"instr" "lag" "last" "last_day" "last_value" "lead" "least" "length"
1016"ln" "localtimestamp" "lower" "lpad" "ltrim" "make_ref" "max" "min"
1017"mod" "months_between" "new_time" "next_day" "nls_charset_decl_len"
1018"nls_charset_id" "nls_charset_name" "nls_initcap" "nls_lower"
1019"nls_upper" "nlssort" "ntile" "nullif" "numtodsinterval"
1020"numtoyminterval" "nvl" "nvl2" "over" "path" "percent_rank"
1021"percentile_cont" "percentile_disc" "power" "preceding" "rank"
1022"ratio_to_report" "rawtohex" "rawtonhex" "reftohex" "regr_"
1023"regr_avgx" "regr_avgy" "regr_count" "regr_intercept" "regr_r2"
1024"regr_slope" "regr_sxx" "regr_sxy" "regr_syy" "replace" "round"
1025"row_number" "rowidtochar" "rowidtonchar" "rpad" "rtrim"
1026"sessiontimezone" "sign" "sin" "sinh" "soundex" "sqrt" "stddev"
1027"stddev_pop" "stddev_samp" "substr" "sum" "sys_connect_by_path"
1028"sys_context" "sys_dburigen" "sys_extract_utc" "sys_guid" "sys_typeid"
1029"sys_xmlagg" "sys_xmlgen" "sysdate" "systimestamp" "tan" "tanh"
1030"to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte"
1031"to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp"
1032"to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc"
1033"tz_offset" "uid" "unbounded" "unistr" "updatexml" "upper" "user"
1034"userenv" "var_pop" "var_samp" "variance" "vsize" "width_bucket" "xml"
1035"xmlagg" "xmlattribute" "xmlcolattval" "xmlconcat" "xmlelement"
1036"xmlforest" "xmlsequence" "xmltransform"
1037))
1038
1039 (oracle-keywords (sql-keywords-re
1040"abort" "access" "accessed" "account" "activate" "add" "admin"
1041"advise" "after" "agent" "aggregate" "all" "allocate" "allow" "alter"
1042"always" "analyze" "ancillary" "and" "any" "apply" "archive"
1043"archivelog" "array" "as" "asc" "associate" "at" "attribute"
1044"attributes" "audit" "authenticated" "authid" "authorization" "auto"
1045"autoallocate" "automatic" "availability" "backup" "before" "begin"
1046"behalf" "between" "binding" "bitmap" "block" "blocksize" "body"
1047"both" "buffer_pool" "build" "by" "cache" "call" "cancel"
1048"cascade" "case" "category" "certificate" "chained" "change" "check"
1049"checkpoint" "child" "chunk" "class" "clear" "clone" "close" "cluster"
1050"column" "column_value" "columns" "comment" "commit" "committed"
1051"compatibility" "compile" "complete" "composite_limit" "compress"
1052"compute" "connect" "connect_time" "consider" "consistent"
1053"constraint" "constraints" "constructor" "contents" "context"
1054"continue" "controlfile" "corruption" "cost" "cpu_per_call"
1055"cpu_per_session" "create" "cross" "cube" "current" "currval" "cycle"
1056"dangling" "data" "database" "datafile" "datafiles" "day" "ddl"
1057"deallocate" "debug" "default" "deferrable" "deferred" "definer"
1058"delay" "delete" "demand" "desc" "determines" "deterministic"
1059"dictionary" "dimension" "directory" "disable" "disassociate"
1060"disconnect" "distinct" "distinguished" "distributed" "dml" "drop"
1061"each" "element" "else" "enable" "end" "equals_path" "escape"
1062"estimate" "except" "exceptions" "exchange" "excluding" "exists"
1063"expire" "explain" "extent" "external" "externally"
1064"failed_login_attempts" "fast" "file" "final" "finish" "flush" "for"
1065"force" "foreign" "freelist" "freelists" "freepools" "fresh" "from"
1066"full" "function" "functions" "generated" "global" "global_name"
1067"globally" "grant" "group" "grouping" "groups" "guard" "hash"
1068"hashkeys" "having" "heap" "hierarchy" "id" "identified" "identifier"
1069"idle_time" "immediate" "in" "including" "increment" "index" "indexed"
1070"indexes" "indextype" "indextypes" "indicator" "initial" "initialized"
1071"initially" "initrans" "inner" "insert" "instance" "instantiable"
1072"instead" "intersect" "into" "invalidate" "is" "isolation" "java"
1073"join" "keep" "key" "kill" "language" "left" "less" "level"
1074"levels" "library" "like" "like2" "like4" "likec" "limit" "link"
1075"list" "lob" "local" "location" "locator" "lock" "log" "logfile"
1076"logging" "logical" "logical_reads_per_call"
1077"logical_reads_per_session" "managed" "management" "manual" "map"
1078"mapping" "master" "matched" "materialized" "maxdatafiles"
1079"maxextents" "maximize" "maxinstances" "maxlogfiles" "maxloghistory"
1080"maxlogmembers" "maxsize" "maxtrans" "maxvalue" "member" "memory"
1081"merge" "migrate" "minextents" "minimize" "minimum" "minus" "minvalue"
1082"mode" "modify" "monitoring" "month" "mount" "move" "movement" "name"
1083"named" "natural" "nested" "never" "new" "next" "nextval" "no"
1084"noarchivelog" "noaudit" "nocache" "nocompress" "nocopy" "nocycle"
1085"nodelay" "noforce" "nologging" "nomapping" "nomaxvalue" "nominimize"
1086"nominvalue" "nomonitoring" "none" "noorder" "noparallel" "norely"
1087"noresetlogs" "noreverse" "normal" "norowdependencies" "nosort"
1088"noswitch" "not" "nothing" "notimeout" "novalidate" "nowait" "null"
1089"nulls" "object" "of" "off" "offline" "oidindex" "old" "on" "online"
1090"only" "open" "operator" "optimal" "option" "or" "order"
1091"organization" "out" "outer" "outline" "overflow" "overriding"
1092"package" "packages" "parallel" "parallel_enable" "parameters"
1093"parent" "partition" "partitions" "password" "password_grace_time"
1094"password_life_time" "password_lock_time" "password_reuse_max"
1095"password_reuse_time" "password_verify_function" "pctfree"
1096"pctincrease" "pctthreshold" "pctused" "pctversion" "percent"
1097"performance" "permanent" "pfile" "physical" "pipelined" "plan"
1098"post_transaction" "pragma" "prebuilt" "preserve" "primary" "private"
1099"private_sga" "privileges" "procedure" "profile" "protection" "public"
1100"purge" "query" "quiesce" "quota" "range" "read" "reads" "rebuild"
1101"records_per_block" "recover" "recovery" "recycle" "reduced" "ref"
1102"references" "referencing" "refresh" "register" "reject" "relational"
1103"rely" "rename" "reset" "resetlogs" "resize" "resolve" "resolver"
1104"resource" "restrict" "restrict_references" "restricted" "result"
1105"resumable" "resume" "retention" "return" "returning" "reuse"
1106"reverse" "revoke" "rewrite" "right" "rnds" "rnps" "role" "roles"
1107"rollback" "rollup" "row" "rowdependencies" "rownum" "rows" "sample"
1108"savepoint" "scan" "schema" "scn" "scope" "segment" "select"
1109"selectivity" "self" "sequence" "serializable" "session"
1110"sessions_per_user" "set" "sets" "settings" "shared" "shared_pool"
1111"shrink" "shutdown" "siblings" "sid" "single" "size" "skip" "some"
1112"sort" "source" "space" "specification" "spfile" "split" "standby"
1113"start" "statement_id" "static" "statistics" "stop" "storage" "store"
1114"structure" "subpartition" "subpartitions" "substitutable"
1115"successful" "supplemental" "suspend" "switch" "switchover" "synonym"
1116"sys" "system" "table" "tables" "tablespace" "tempfile" "template"
1117"temporary" "test" "than" "then" "thread" "through" "time_zone"
1118"timeout" "to" "trace" "transaction" "trigger" "triggers" "truncate"
1119"trust" "type" "types" "unarchived" "under" "under_path" "undo"
1120"uniform" "union" "unique" "unlimited" "unlock" "unquiesce"
1121"unrecoverable" "until" "unusable" "unused" "update" "upgrade" "usage"
1122"use" "using" "validate" "validation" "value" "values" "variable"
1123"varray" "version" "view" "wait" "when" "whenever" "where" "with"
1124"without" "wnds" "wnps" "work" "write" "xmldata" "xmlschema" "xmltype"
1125))
1126
1127 (oracle-types (sql-keywords-re
1128"bfile" "blob" "byte" "char" "character" "clob" "date" "dec" "decimal"
1129"double" "float" "int" "integer" "interval" "long" "national" "nchar"
1130"nclob" "number" "numeric" "nvarchar2" "precision" "raw" "real"
1131"rowid" "second" "smallint" "time" "timestamp" "urowid" "varchar"
1132"varchar2" "varying" "year" "zone"
1133))
1134
1135 (plsql-functions (sql-keywords-re
1136"%bulk_rowcount" "%found" "%isopen" "%notfound" "%rowcount" "%rowtype"
1137"%type" "extend" "prior"
1138))
1139
1140 (plsql-keywords (sql-keywords-re
1141"autonomous_transaction" "bulk" "char_base" "collect" "constant"
1142"cursor" "declare" "do" "elsif" "exception_init" "execute" "exit"
1143"extends" "false" "fetch" "forall" "goto" "hour" "if" "interface"
1144"loop" "minute" "number_base" "ocirowid" "opaque" "others" "rowtype"
1145"separate" "serially_reusable" "sql" "sqlcode" "sqlerrm" "subtype"
1146"the" "timezone_abbr" "timezone_hour" "timezone_minute"
1147"timezone_region" "true" "varrying" "while"
1148))
1149
1150 (plsql-type (sql-keywords-re
1151"binary_integer" "boolean" "naturaln" "pls_integer" "positive"
1152"positiven" "record" "signtype" "string"
1153))
1154
1155 (plsql-warning (sql-keywords-re
78024f88
AS
1156"access_into_null" "case_not_found" "collection_is_null"
1157"cursor_already_open" "dup_val_on_index" "invalid_cursor"
77d352a6 1158"invalid_number" "login_denied" "no_data_found" "not_logged_on"
78024f88
AS
1159"program_error" "rowtype_mismatch" "self_is_null" "storage_error"
1160"subscript_beyond_count" "subscript_outside_limit" "sys_invalid_rowid"
1161"timeout_on_resource" "too_many_rows" "value_error" "zero_divide"
1162"exception" "notfound"
9fd8cb36 1163))
78024f88 1164
9fd8cb36
SM
1165 (sqlplus-commands
1166 (eval-when-compile (concat "^\\(\\("
1167 (regexp-opt '(
78024f88
AS
1168"@" "@@" "accept" "append" "archive" "attribute" "break"
1169"btitle" "change" "clear" "column" "connect" "copy" "define"
1170"del" "describe" "disconnect" "edit" "execute" "exit" "get" "help"
1171"host" "input" "list" "password" "pause" "print" "prompt" "recover"
1172"remark" "repfooter" "repheader" "run" "save" "show" "shutdown"
1173"spool" "start" "startup" "store" "timing" "ttitle" "undefine"
1174"variable" "whenever"
1175
1176) t)
1177
1178 "\\)\\|"
1179 "\\(compute\\s-+\\(avg\\|cou\\|min\\|max\\|num\\|sum\\|std\\|var\\)\\)\\|"
1180 "\\(set\\s-+\\(appi\\(nfo\\)?\\|array\\(size\\)?\\|"
1181 "auto\\(commit\\)?\\|autop\\(rint\\)?\\|autorecovery\\|"
1182 "autot\\(race\\)?\\|blo\\(ckterminator\\)?\\|cmds\\(ep\\)?\\|"
1183 "colsep\\|com\\(patibility\\)?\\|con\\(cat\\)?\\|"
1184 "copyc\\(ommit\\)?\\|copytypecheck\\|def\\(ine\\)?\\|"
1185 "describe\\|echo\\|editf\\(ile\\)?\\|emb\\(edded\\)?\\|"
1186 "esc\\(ape\\)?\\|feed\\(back\\)?\\|flagger\\|"
1187 "flu\\(sh\\)?\\|hea\\(ding\\)?\\|heads\\(ep\\)?\\|"
1188 "instance\\|lin\\(esize\\)?\\|lobof\\(fset\\)?\\|"
1189 "logsource\\|long\\|longc\\(hunksize\\)?\\|mark\\(up\\)?\\|"
1190 "newp\\(age\\)?\\|null\\|numf\\(ormat\\)?\\|"
1191 "num\\(width\\)?\\|pages\\(ize\\)?\\|pau\\(se\\)?\\|"
1192 "recsep\\|recsepchar\\|serverout\\(put\\)?\\|"
1193 "shift\\(inout\\)?\\|show\\(mode\\)?\\|"
1194 "sqlbl\\(anklines\\)?\\|sqlc\\(ase\\)?\\|"
1195 "sqlco\\(ntinue\\)?\\|sqln\\(umber\\)?\\|"
1196 "sqlpluscompat\\(ibility\\)?\\|sqlpre\\(fix\\)?\\|"
1197 "sqlp\\(rompt\\)?\\|sqlt\\(erminator\\)?\\|"
1198 "suf\\(fix\\)?\\|tab\\|term\\(out\\)?\\|ti\\(me\\)?\\|"
1199 "timi\\(ng\\)?\\|trim\\(out\\)?\\|trims\\(pool\\)?\\|"
1200 "und\\(erline\\)?\\|ver\\(ify\\)?\\|wra\\(p\\)?\\)\\)\\)"
1201 "\\b.*$"
9fd8cb36 1202 ))))
78024f88 1203
9a9069c9
SM
1204 `((,sqlplus-commands . font-lock-doc-face)
1205 (,oracle-functions . font-lock-builtin-face)
9fd8cb36
SM
1206 (,oracle-keywords . font-lock-keyword-face)
1207 (,oracle-types . font-lock-type-face)
9a9069c9 1208 (,plsql-functions . font-lock-builtin-face)
9fd8cb36
SM
1209 (,plsql-keywords . font-lock-keyword-face)
1210 (,plsql-type . font-lock-type-face)
1211 (,plsql-warning . font-lock-warning-face)))
95e4b2ef 1212
78024f88 1213 "Oracle SQL keywords used by font-lock.
95e4b2ef
RS
1214
1215This variable is used by `sql-mode' and `sql-interactive-mode'. The
1216regular expressions are created during compilation by calling the
1217function `regexp-opt'. Therefore, take a look at the source before
78024f88
AS
1218you define your own sql-mode-oracle-font-lock-keywords. You may want
1219to add functions and PL/SQL keywords.")
95e4b2ef 1220
78024f88 1221(defvar sql-mode-postgres-font-lock-keywords
9fd8cb36
SM
1222 (let ((pg-funcs (sql-keywords-re
1223"abbrev" "abs" "acos" "age" "area" "ascii" "asin" "atab2" "atan"
1224"atan2" "avg" "bit_length" "both" "broadcast" "btrim" "cbrt" "ceil"
1225"center" "char_length" "chr" "coalesce" "col_description" "convert"
1226"cos" "cot" "count" "current_database" "current_date" "current_schema"
1227"current_schemas" "current_setting" "current_time" "current_timestamp"
1228"current_user" "currval" "date_part" "date_trunc" "decode" "degrees"
1229"diameter" "encode" "exp" "extract" "floor" "get_bit" "get_byte"
1230"has_database_privilege" "has_function_privilege"
1231"has_language_privilege" "has_schema_privilege" "has_table_privilege"
1232"height" "host" "initcap" "isclosed" "isfinite" "isopen" "leading"
1233"length" "ln" "localtime" "localtimestamp" "log" "lower" "lpad"
1234"ltrim" "masklen" "max" "min" "mod" "netmask" "network" "nextval"
1235"now" "npoints" "nullif" "obj_description" "octet_length" "overlay"
1236"pclose" "pg_client_encoding" "pg_function_is_visible"
1237"pg_get_constraintdef" "pg_get_indexdef" "pg_get_ruledef"
1238"pg_get_userbyid" "pg_get_viewdef" "pg_opclass_is_visible"
1239"pg_operator_is_visible" "pg_table_is_visible" "pg_type_is_visible"
1240"pi" "popen" "position" "pow" "quote_ident" "quote_literal" "radians"
1241"radius" "random" "repeat" "replace" "round" "rpad" "rtrim"
1242"session_user" "set_bit" "set_byte" "set_config" "set_masklen"
1243"setval" "sign" "sin" "split_part" "sqrt" "stddev" "strpos" "substr"
1244"substring" "sum" "tan" "timeofday" "to_ascii" "to_char" "to_date"
1245"to_hex" "to_number" "to_timestamp" "trailing" "translate" "trim"
1246"trunc" "upper" "variance" "version" "width"
1247))
1248
1249 (pg-reserved (sql-keywords-re
1250"abort" "access" "add" "after" "aggregate" "alignment" "all" "alter"
1251"analyze" "and" "any" "as" "asc" "assignment" "authorization"
1252"backward" "basetype" "before" "begin" "between" "binary" "by" "cache"
1253"called" "cascade" "case" "cast" "characteristics" "check"
1254"checkpoint" "class" "close" "cluster" "column" "comment" "commit"
1255"committed" "commutator" "constraint" "constraints" "conversion"
1256"copy" "create" "createdb" "createuser" "cursor" "cycle" "database"
1257"deallocate" "declare" "default" "deferrable" "deferred" "definer"
1258"delete" "delimiter" "desc" "distinct" "do" "domain" "drop" "each"
1259"element" "else" "encoding" "encrypted" "end" "escape" "except"
1260"exclusive" "execute" "exists" "explain" "extended" "external" "false"
1261"fetch" "finalfunc" "for" "force" "foreign" "forward" "freeze" "from"
1262"full" "function" "grant" "group" "gtcmp" "handler" "hashes" "having"
1263"immediate" "immutable" "implicit" "in" "increment" "index" "inherits"
1264"initcond" "initially" "input" "insensitive" "insert" "instead"
1265"internallength" "intersect" "into" "invoker" "is" "isnull"
1266"isolation" "join" "key" "language" "leftarg" "level" "like" "limit"
1267"listen" "load" "local" "location" "lock" "ltcmp" "main" "match"
1268"maxvalue" "merges" "minvalue" "mode" "move" "natural" "negator"
1269"next" "nocreatedb" "nocreateuser" "none" "not" "nothing" "notify"
1270"notnull" "null" "of" "offset" "oids" "on" "only" "operator" "or"
1271"order" "output" "owner" "partial" "passedbyvalue" "password" "plain"
1272"prepare" "primary" "prior" "privileges" "procedural" "procedure"
1273"public" "read" "recheck" "references" "reindex" "relative" "rename"
1274"reset" "restrict" "returns" "revoke" "rightarg" "rollback" "row"
1275"rule" "schema" "scroll" "security" "select" "sequence" "serializable"
1276"session" "set" "sfunc" "share" "show" "similar" "some" "sort1"
1277"sort2" "stable" "start" "statement" "statistics" "storage" "strict"
1278"stype" "sysid" "table" "temp" "template" "temporary" "then" "to"
1279"transaction" "trigger" "true" "truncate" "trusted" "type"
1280"unencrypted" "union" "unique" "unknown" "unlisten" "until" "update"
1281"usage" "user" "using" "vacuum" "valid" "validator" "values"
1282"variable" "verbose" "view" "volatile" "when" "where" "with" "without"
1283"work"
1284))
1285
1286 (pg-types (sql-keywords-re
1287"anyarray" "bigint" "bigserial" "bit" "boolean" "box" "bytea" "char"
1288"character" "cidr" "circle" "cstring" "date" "decimal" "double"
1289"float4" "float8" "inet" "int2" "int4" "int8" "integer" "internal"
1290"interval" "language_handler" "line" "lseg" "macaddr" "money"
1291"numeric" "oid" "opaque" "path" "point" "polygon" "precision" "real"
1292"record" "regclass" "regoper" "regoperator" "regproc" "regprocedure"
1293"regtype" "serial" "serial4" "serial8" "smallint" "text" "time"
1294"timestamp" "varchar" "varying" "void" "zone"
1295)))
1296
9a9069c9 1297 `((,pg-funcs . font-lock-builtin-face)
9fd8cb36
SM
1298 (,pg-reserved . font-lock-keyword-face)
1299 (,pg-types . font-lock-type-face)))
95e4b2ef 1300
78024f88 1301 "Postgres SQL keywords used by font-lock.
f4df536d
JB
1302
1303This variable is used by `sql-mode' and `sql-interactive-mode'. The
1304regular expressions are created during compilation by calling the
78024f88
AS
1305function `regexp-opt'. Therefore, take a look at the source before
1306you define your own sql-mode-postgres-font-lock-keywords.")
f4df536d 1307
78024f88 1308(defvar sql-mode-linter-font-lock-keywords
9fd8cb36 1309 (let ((linter-keywords (sql-keywords-re
f4df536d
JB
1310"autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel"
1311"committed" "count" "countblob" "cross" "current" "data" "database"
1312"datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred"
1313"denied" "description" "device" "difference" "directory" "error"
1314"escape" "euc" "exclusive" "external" "extfile" "false" "file"
1315"filename" "filesize" "filetime" "filter" "findblob" "first" "foreign"
1316"full" "fuzzy" "global" "granted" "ignore" "immediate" "increment"
1317"indexes" "indexfile" "indexfiles" "indextime" "initial" "integrity"
1318"internal" "key" "last_autoinc" "last_rowid" "limit" "linter"
1319"linter_file_device" "linter_file_size" "linter_name_length" "ln"
1320"local" "login" "maxisn" "maxrow" "maxrowid" "maxvalue" "message"
1321"minvalue" "module" "names" "national" "natural" "new" "new_table"
1322"no" "node" "noneuc" "nulliferror" "numbers" "off" "old" "old_table"
1323"only" "operation" "optimistic" "option" "page" "partially" "password"
1324"phrase" "plan" "precision" "primary" "priority" "privileges"
1325"proc_info_size" "proc_par_name_len" "protocol" "quant" "range" "raw"
1326"read" "record" "records" "references" "remote" "rename" "replication"
1327"restart" "rewrite" "root" "row" "rule" "savepoint" "security"
1328"sensitive" "sequence" "serializable" "server" "since" "size" "some"
1329"startup" "statement" "station" "success" "sys_guid" "tables" "test"
1330"timeout" "trace" "transaction" "translation" "trigger"
1331"trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown"
1332"unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes"
1333"wait" "windows_code" "workspace" "write" "xml"
9fd8cb36 1334))
78024f88 1335
9fd8cb36 1336 (linter-reserved (sql-keywords-re
f4df536d
JB
1337"access" "action" "add" "address" "after" "all" "alter" "always" "and"
1338"any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit"
1339"aud_obj_name_len" "backup" "base" "before" "between" "blobfile"
1340"blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check"
1341"clear" "close" "column" "comment" "commit" "connect" "contains"
1342"correct" "create" "delete" "desc" "disable" "disconnect" "distinct"
1343"drop" "each" "ef" "else" "enable" "end" "event" "except" "exclude"
1344"execute" "exists" "extract" "fetch" "finish" "for" "from" "get"
1345"grant" "group" "having" "identified" "in" "index" "inner" "insert"
1346"instead" "intersect" "into" "is" "isolation" "join" "left" "level"
1347"like" "lock" "mode" "modify" "not" "nowait" "null" "of" "on" "open"
1348"or" "order" "outer" "owner" "press" "prior" "procedure" "public"
1349"purge" "rebuild" "resource" "restrict" "revoke" "right" "role"
1350"rollback" "rownum" "select" "session" "set" "share" "shutdown"
1351"start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then"
1352"to" "union" "unique" "unlock" "until" "update" "using" "values"
1353"view" "when" "where" "with" "without"
9fd8cb36 1354))
78024f88 1355
9fd8cb36 1356 (linter-types (sql-keywords-re
f4df536d
JB
1357"bigint" "bitmap" "blob" "boolean" "char" "character" "date"
1358"datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar"
1359"number" "numeric" "real" "smallint" "varbyte" "varchar" "byte"
1360"cursor" "long"
9fd8cb36 1361))
78024f88 1362
9fd8cb36 1363 (linter-functions (sql-keywords-re
f4df536d
JB
1364"abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime"
1365"exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw"
1366"getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log"
1367"lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl"
1368"octet_length" "power" "rand" "rawtohex" "repeat_string"
1369"right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex"
1370"sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date"
1371"to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode"
1372"substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap"
1373"instr" "least" "multime" "replace" "width"
9fd8cb36 1374)))
78024f88 1375
9fd8cb36
SM
1376 `((,linter-keywords . font-lock-keyword-face)
1377 (,linter-reserved . font-lock-keyword-face)
9a9069c9 1378 (,linter-functions . font-lock-builtin-face)
9fd8cb36 1379 (,linter-types . font-lock-type-face)))
78024f88
AS
1380
1381 "Linter SQL keywords used by font-lock.
f4df536d 1382
78024f88
AS
1383This variable is used by `sql-mode' and `sql-interactive-mode'. The
1384regular expressions are created during compilation by calling the
1385function `regexp-opt'.")
1386
1387(defvar sql-mode-ms-font-lock-keywords
9fd8cb36 1388 (let ((ms-reserved (sql-keywords-re
78024f88
AS
1389"absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization"
1390"avg" "backup" "begin" "between" "break" "browse" "bulk" "by"
1391"cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce"
1392"column" "commit" "committed" "compute" "confirm" "constraint"
1393"contains" "containstable" "continue" "controlrow" "convert" "count"
1394"create" "cross" "current" "current_date" "current_time"
9fd8cb36
SM
1395"current_timestamp" "current_user" "database" "deallocate" "declare"
1396"default" "delete" "deny" "desc" "disk" "distinct" "distributed"
1397"double" "drop" "dummy" "dump" "else" "end" "errlvl" "errorexit"
1398"escape" "except" "exec" "execute" "exists" "exit" "fetch" "file"
1399"fillfactor" "first" "floppy" "for" "foreign" "freetext"
78024f88
AS
1400"freetexttable" "from" "full" "goto" "grant" "group" "having"
1401"holdlock" "identity" "identity_insert" "identitycol" "if" "in"
1402"index" "inner" "insert" "intersect" "into" "is" "isolation" "join"
1403"key" "kill" "last" "left" "level" "like" "lineno" "load" "max" "min"
1404"mirrorexit" "national" "next" "nocheck" "nolock" "nonclustered" "not"
1405"null" "nullif" "of" "off" "offsets" "on" "once" "only" "open"
1406"opendatasource" "openquery" "openrowset" "option" "or" "order"
1407"outer" "output" "over" "paglock" "percent" "perm" "permanent" "pipe"
1408"plan" "precision" "prepare" "primary" "print" "prior" "privileges"
1409"proc" "procedure" "processexit" "public" "raiserror" "read"
1410"readcommitted" "readpast" "readtext" "readuncommitted" "reconfigure"
1411"references" "relative" "repeatable" "repeatableread" "replication"
1412"restore" "restrict" "return" "revoke" "right" "rollback" "rowcount"
1413"rowguidcol" "rowlock" "rule" "save" "schema" "select" "serializable"
1414"session_user" "set" "shutdown" "some" "statistics" "sum"
1415"system_user" "table" "tablock" "tablockx" "tape" "temp" "temporary"
1416"textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate"
1417"tsequal" "uncommitted" "union" "unique" "update" "updatetext"
1418"updlock" "use" "user" "values" "view" "waitfor" "when" "where"
9fd8cb36
SM
1419"while" "with" "work" "writetext" "collate" "function" "openxml"
1420"returns"
1421))
78024f88 1422
9fd8cb36 1423 (ms-types (sql-keywords-re
78024f88
AS
1424"binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal"
1425"double" "float" "image" "int" "integer" "money" "national" "nchar"
1426"ntext" "numeric" "numeric" "nvarchar" "precision" "real"
1427"smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint"
1428"uniqueidentifier" "varbinary" "varchar" "varying"
9fd8cb36 1429))
78024f88
AS
1430
1431 (ms-vars "\\b@[a-zA-Z0-9_]*\\b")
1432
9fd8cb36 1433 (ms-functions (sql-keywords-re
78024f88
AS
1434"@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts"
1435"@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy"
1436"@@langid" "@@language" "@@lock_timeout" "@@max_connections"
1437"@@max_precision" "@@nestlevel" "@@options" "@@pack_received"
1438"@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount"
1439"@@servername" "@@servicename" "@@spid" "@@textsize" "@@timeticks"
1440"@@total_errors" "@@total_read" "@@total_write" "@@trancount"
1441"@@version" "abs" "acos" "and" "app_name" "ascii" "asin" "atan" "atn2"
1442"avg" "case" "cast" "ceiling" "char" "charindex" "coalesce"
1443"col_length" "col_name" "columnproperty" "containstable" "convert"
1444"cos" "cot" "count" "current_timestamp" "current_user" "cursor_status"
1445"databaseproperty" "datalength" "dateadd" "datediff" "datename"
1446"datepart" "day" "db_id" "db_name" "degrees" "difference" "exp"
1447"file_id" "file_name" "filegroup_id" "filegroup_name"
1448"filegroupproperty" "fileproperty" "floor" "formatmessage"
1449"freetexttable" "fulltextcatalogproperty" "fulltextserviceproperty"
1450"getansinull" "getdate" "grouping" "host_id" "host_name" "ident_incr"
1451"ident_seed" "identity" "index_col" "indexproperty" "is_member"
1452"is_srvrolemember" "isdate" "isnull" "isnumeric" "left" "len" "log"
1453"log10" "lower" "ltrim" "max" "min" "month" "nchar" "newid" "nullif"
1454"object_id" "object_name" "objectproperty" "openquery" "openrowset"
1455"parsename" "patindex" "patindex" "permissions" "pi" "power"
1456"quotename" "radians" "rand" "replace" "replicate" "reverse" "right"
1457"round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt"
1458"square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum"
1459"suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan"
1460"textptr" "textvalid" "typeproperty" "unicode" "upper" "user"
1461"user_id" "user_name" "var" "varp" "year"
9fd8cb36 1462))
78024f88 1463
9fd8cb36 1464 (ms-commands
78024f88
AS
1465 (eval-when-compile
1466 (concat "^\\(\\(set\\s-+\\("
1467 (regexp-opt '(
78024f88
AS
1468"datefirst" "dateformat" "deadlock_priority" "lock_timeout"
1469"concat_null_yields_null" "cursor_close_on_commit"
1470"disable_def_cnst_chk" "fips_flagger" "identity_insert" "language"
1471"offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly"
1472"nocount" "noexec" "numeric_roundabort" "parseonly"
1473"query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults"
1474"ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding"
1475"ansi_warnings" "forceplan" "showplan_all" "showplan_text"
1476"statistics" "implicit_transactions" "remote_proc_transactions"
1477"transaction" "xact_abort"
78024f88
AS
1478) t)
1479 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$"))))
1480
9a9069c9 1481 `((,ms-commands . font-lock-doc-face)
9fd8cb36 1482 (,ms-reserved . font-lock-keyword-face)
9a9069c9 1483 (,ms-functions . font-lock-builtin-face)
9fd8cb36
SM
1484 (,ms-vars . font-lock-variable-name-face)
1485 (,ms-types . font-lock-type-face)))
78024f88
AS
1486
1487 "Microsoft SQLServer SQL keywords used by font-lock.
1488
1489This variable is used by `sql-mode' and `sql-interactive-mode'. The
1490regular expressions are created during compilation by calling the
1491function `regexp-opt'. Therefore, take a look at the source before
1492you define your own sql-mode-ms-font-lock-keywords.")
1493
9fd8cb36 1494(defvar sql-mode-sybase-font-lock-keywords nil
78024f88
AS
1495 "Sybase SQL keywords used by font-lock.
1496
1497This variable is used by `sql-mode' and `sql-interactive-mode'. The
1498regular expressions are created during compilation by calling the
1499function `regexp-opt'. Therefore, take a look at the source before
1500you define your own sql-mode-sybase-font-lock-keywords.")
1501
9fd8cb36 1502(defvar sql-mode-informix-font-lock-keywords nil
78024f88
AS
1503 "Informix SQL keywords used by font-lock.
1504
1505This variable is used by `sql-mode' and `sql-interactive-mode'. The
1506regular expressions are created during compilation by calling the
1507function `regexp-opt'. Therefore, take a look at the source before
1508you define your own sql-mode-informix-font-lock-keywords.")
1509
9fd8cb36 1510(defvar sql-mode-interbase-font-lock-keywords nil
78024f88
AS
1511 "Interbase SQL keywords used by font-lock.
1512
1513This variable is used by `sql-mode' and `sql-interactive-mode'. The
1514regular expressions are created during compilation by calling the
1515function `regexp-opt'. Therefore, take a look at the source before
1516you define your own sql-mode-interbase-font-lock-keywords.")
1517
9fd8cb36 1518(defvar sql-mode-ingres-font-lock-keywords nil
78024f88
AS
1519 "Ingres SQL keywords used by font-lock.
1520
1521This variable is used by `sql-mode' and `sql-interactive-mode'. The
1522regular expressions are created during compilation by calling the
1523function `regexp-opt'. Therefore, take a look at the source before
1524you define your own sql-mode-interbase-font-lock-keywords.")
1525
9fd8cb36 1526(defvar sql-mode-solid-font-lock-keywords nil
78024f88
AS
1527 "Solid SQL keywords used by font-lock.
1528
1529This variable is used by `sql-mode' and `sql-interactive-mode'. The
1530regular expressions are created during compilation by calling the
1531function `regexp-opt'. Therefore, take a look at the source before
1532you define your own sql-mode-solid-font-lock-keywords.")
1533
9fd8cb36
SM
1534(defvar sql-mode-mysql-font-lock-keywords
1535 (let ((mysql-funcs (sql-keywords-re
1536"ascii" "avg" "bdmpolyfromtext" "bdmpolyfromwkb" "bdpolyfromtext"
1537"bdpolyfromwkb" "benchmark" "bin" "bit_and" "bit_length" "bit_or"
1538"bit_xor" "both" "cast" "char_length" "character_length" "coalesce"
1539"concat" "concat_ws" "connection_id" "conv" "convert" "count"
1540"curdate" "current_date" "current_time" "current_timestamp" "curtime"
1541"elt" "encrypt" "export_set" "field" "find_in_set" "found_rows" "from"
1542"geomcollfromtext" "geomcollfromwkb" "geometrycollectionfromtext"
1543"geometrycollectionfromwkb" "geometryfromtext" "geometryfromwkb"
1544"geomfromtext" "geomfromwkb" "get_lock" "group_concat" "hex" "ifnull"
1545"instr" "interval" "isnull" "last_insert_id" "lcase" "leading"
1546"length" "linefromtext" "linefromwkb" "linestringfromtext"
1547"linestringfromwkb" "load_file" "locate" "lower" "lpad" "ltrim"
1548"make_set" "master_pos_wait" "max" "mid" "min" "mlinefromtext"
1549"mlinefromwkb" "mpointfromtext" "mpointfromwkb" "mpolyfromtext"
1550"mpolyfromwkb" "multilinestringfromtext" "multilinestringfromwkb"
1551"multipointfromtext" "multipointfromwkb" "multipolygonfromtext"
1552"multipolygonfromwkb" "now" "nullif" "oct" "octet_length" "ord"
1553"pointfromtext" "pointfromwkb" "polyfromtext" "polyfromwkb"
1554"polygonfromtext" "polygonfromwkb" "position" "quote" "rand"
1555"release_lock" "repeat" "replace" "reverse" "rpad" "rtrim" "soundex"
1556"space" "std" "stddev" "substring" "substring_index" "sum" "sysdate"
1557"trailing" "trim" "ucase" "unix_timestamp" "upper" "user" "variance"
1558))
1559
1560 (mysql-keywords (sql-keywords-re
1561"action" "add" "after" "against" "all" "alter" "and" "as" "asc"
1562"auto_increment" "avg_row_length" "bdb" "between" "by" "cascade"
1563"case" "change" "character" "check" "checksum" "close" "collate"
1564"collation" "column" "columns" "comment" "committed" "concurrent"
1565"constraint" "create" "cross" "data" "database" "default"
1566"delay_key_write" "delayed" "delete" "desc" "directory" "disable"
1567"distinct" "distinctrow" "do" "drop" "dumpfile" "duplicate" "else"
1568"enable" "enclosed" "end" "escaped" "exists" "fields" "first" "for"
1569"force" "foreign" "from" "full" "fulltext" "global" "group" "handler"
1570"having" "heap" "high_priority" "if" "ignore" "in" "index" "infile"
1571"inner" "insert" "insert_method" "into" "is" "isam" "isolation" "join"
1572"key" "keys" "last" "left" "level" "like" "limit" "lines" "load"
1573"local" "lock" "low_priority" "match" "max_rows" "merge" "min_rows"
1574"mode" "modify" "mrg_myisam" "myisam" "natural" "next" "no" "not"
1575"null" "offset" "oj" "on" "open" "optionally" "or" "order" "outer"
1576"outfile" "pack_keys" "partial" "password" "prev" "primary"
1577"procedure" "quick" "raid0" "raid_type" "read" "references" "rename"
1578"repeatable" "restrict" "right" "rollback" "rollup" "row_format"
1579"savepoint" "select" "separator" "serializable" "session" "set"
1580"share" "show" "sql_big_result" "sql_buffer_result" "sql_cache"
1581"sql_calc_found_rows" "sql_no_cache" "sql_small_result" "starting"
1582"straight_join" "striped" "table" "tables" "temporary" "terminated"
1583"then" "to" "transaction" "truncate" "type" "uncommitted" "union"
1584"unique" "unlock" "update" "use" "using" "values" "when" "where"
1585"with" "write" "xor"
1586))
1587
1588 (mysql-types (sql-keywords-re
1589"bigint" "binary" "bit" "blob" "bool" "boolean" "char" "curve" "date"
1590"datetime" "dec" "decimal" "double" "enum" "fixed" "float" "geometry"
1591"geometrycollection" "int" "integer" "line" "linearring" "linestring"
1592"longblob" "longtext" "mediumblob" "mediumint" "mediumtext"
1593"multicurve" "multilinestring" "multipoint" "multipolygon"
1594"multisurface" "national" "numeric" "point" "polygon" "precision"
1595"real" "smallint" "surface" "text" "time" "timestamp" "tinyblob"
1596"tinyint" "tinytext" "unsigned" "varchar" "year" "year2" "year4"
1597"zerofill"
1598)))
1599
9a9069c9 1600 `((,mysql-funcs . font-lock-builtin-face)
9fd8cb36
SM
1601 (,mysql-keywords . font-lock-keyword-face)
1602 (,mysql-types . font-lock-type-face)))
1603
78024f88
AS
1604 "MySQL SQL keywords used by font-lock.
1605
1606This variable is used by `sql-mode' and `sql-interactive-mode'. The
1607regular expressions are created during compilation by calling the
1608function `regexp-opt'. Therefore, take a look at the source before
1609you define your own sql-mode-mysql-font-lock-keywords.")
1610
9fd8cb36 1611(defvar sql-mode-sqlite-font-lock-keywords nil
78024f88
AS
1612 "SQLite SQL keywords used by font-lock.
1613
1614This variable is used by `sql-mode' and `sql-interactive-mode'. The
1615regular expressions are created during compilation by calling the
1616function `regexp-opt'. Therefore, take a look at the source before
1617you define your own sql-mode-sqlite-font-lock-keywords.")
1618
9fd8cb36 1619(defvar sql-mode-db2-font-lock-keywords nil
78024f88
AS
1620 "DB2 SQL keywords used by font-lock.
1621
1622This variable is used by `sql-mode' and `sql-interactive-mode'. The
1623regular expressions are created during compilation by calling the
1624function `regexp-opt'. Therefore, take a look at the source before
1625you define your own sql-mode-db2-font-lock-keywords.")
1626
1627(defvar sql-mode-font-lock-keywords nil
95e4b2ef
RS
1628 "SQL keywords used by font-lock.
1629
78024f88
AS
1630Setting this variable directly no longer has any affect. Use
1631`sql-product' and `sql-add-product-keywords' to control the
1632highlighting rules in sql-mode.")
1633
1634\f
1635
1636;;; SQL Product support functions
1637
1638(defun sql-product-feature (feature &optional product)
1639 "Lookup `feature' needed to support the current SQL product.
1640
9fd8cb36
SM
1641See \[sql-product-alist] for a list of products and supported features."
1642 (plist-get
1643 (cdr (assoc (or product sql-product)
1644 sql-product-alist))
1645 feature))
78024f88
AS
1646
1647(defun sql-product-font-lock (keywords-only imenu)
1648 "Sets `font-lock-defaults' and `font-lock-keywords' based on
1649the product-specific keywords and syntax-alists defined in
9fd8cb36 1650`sql-product-alist'."
78024f88
AS
1651 (let
1652 ;; Get the product-specific syntax-alist.
1653 ((syntax-alist
1654 (append
1655 (sql-product-feature :syntax-alist)
1656 '((?_ . "w") (?. . "w")))))
1657
1658 ;; Get the product-specific keywords.
1659 (setq sql-mode-font-lock-keywords
1660 (append
9a9069c9
SM
1661 (unless (eq sql-product 'ansi)
1662 (eval (sql-product-feature :font-lock)))
1663 ;; Always highlight ANSI keywords
9fd8cb36 1664 (eval (sql-product-feature :font-lock 'ansi))
9a9069c9
SM
1665 ;; Fontify object names in CREATE, DROP and ALTER DDL
1666 ;; statements
78024f88
AS
1667 (list sql-mode-font-lock-object-name)))
1668
9a9069c9
SM
1669 ;; Setup font-lock. Force re-parsing of `font-lock-defaults'.
1670 (set (make-local-variable 'font-lock-set-defaults) nil)
1671 (setq font-lock-defaults (list 'sql-mode-font-lock-keywords
78024f88
AS
1672 keywords-only t syntax-alist))
1673
9a9069c9
SM
1674 ;; Force font lock to reinitialize if it is already on
1675 ;; Otherwise, we can wait until it can be started.
1676 (when (and (fboundp 'font-lock-mode)
1677 font-lock-mode)
1678 (font-lock-mode-internal nil)
1679 (font-lock-mode-internal t))
1680
1681 (add-hook 'font-lock-mode-hook
1682 (lambda ()
1683 ;; Provide defaults for new font-lock faces.
1684 (defvar font-lock-builtin-face
1685 (if (boundp 'font-lock-preprocessor-face)
1686 font-lock-preprocessor-face
1687 font-lock-keyword-face))
1688 (defvar font-lock-doc-face font-lock-string-face))
1689 nil t)
1690
78024f88
AS
1691 ;; Setup imenu; it needs the same syntax-alist.
1692 (when imenu
1693 (setq imenu-syntax-alist syntax-alist))))
1694
1695;;;###autoload
9fd8cb36
SM
1696(defun sql-add-product-keywords (product keywords &optional append)
1697 "Add highlighting KEYWORDS for SQL PRODUCT.
1698
1699PRODUCT should be a symbol, the name of a sql product, such as
1700`oracle'. KEYWORDS should be a list; see the variable
1701`font-lock-keywords'. By default they are added at the beginning
1702of the current highlighting list. If optional argument APPEND is
1703`set', they are used to replace the current highlighting list.
1704If APPEND is any other non-nil value, they are added at the end
1705of the current highlighting list.
1706
1707For example:
1708
1709 (sql-add-product-keywords 'ms
1710 '((\"\\\\b\\\\w+_t\\\\b\" . font-lock-type-face)))
1711
1712adds a fontification pattern to fontify identifiers ending in
1713`_t' as data types."
1714
1715 (let ((font-lock (sql-product-feature :font-lock product))
1716 old)
1717 (setq old (eval font-lock))
1718 (set font-lock
1719 (if (eq append 'set)
1720 keywords
1721 (if append
1722 (append old keywords)
1723 (append keywords old))))))
95e4b2ef
RS
1724
1725\f
c0bbaf57 1726
624ef9b3
GM
1727;;; Functions to switch highlighting
1728
78024f88
AS
1729(defun sql-highlight-product ()
1730 "Turns on the appropriate font highlighting for the SQL product
1731selected."
1732
1733 (when (eq major-mode 'sql-mode)
1734 ;; Setup font-lock
1735 (sql-product-font-lock nil t)
1736
78024f88
AS
1737 ;; Set the mode name to include the product.
1738 (setq mode-name (concat "SQL[" (prin1-to-string sql-product) "]"))))
1739
1740(defun sql-set-product (product)
1741 "Set `sql-product' to product and enable appropriate
1742highlighting."
1743 (interactive "SEnter SQL product: ")
9fd8cb36 1744 (when (not (assoc product sql-product-alist))
78024f88
AS
1745 (error "SQL product %s is not supported; treated as ANSI" product)
1746 (setq product 'ansi))
1747
1748 ;; Save product setting and fontify.
1749 (setq sql-product product)
1750 (sql-highlight-product))
1751
624ef9b3 1752(defun sql-highlight-oracle-keywords ()
78024f88 1753 "Highlight Oracle keywords."
624ef9b3 1754 (interactive)
78024f88 1755 (sql-set-product 'oracle))
624ef9b3
GM
1756
1757(defun sql-highlight-postgres-keywords ()
78024f88 1758 "Highlight Postgres keywords."
624ef9b3 1759 (interactive)
78024f88 1760 (sql-set-product 'postgres))
624ef9b3 1761
f4df536d 1762(defun sql-highlight-linter-keywords ()
78024f88
AS
1763 "Highlight LINTER keywords."
1764 (interactive)
1765 (sql-set-product 'linter))
1766
1767(defun sql-highlight-ms-keywords ()
1768 "Highlight Microsoft SQLServer keywords."
f4df536d 1769 (interactive)
78024f88 1770 (sql-set-product 'ms))
f4df536d 1771
624ef9b3 1772(defun sql-highlight-ansi-keywords ()
78024f88 1773 "Highlight ANSI SQL keywords."
624ef9b3 1774 (interactive)
78024f88
AS
1775 (sql-set-product 'ansi))
1776
1777(defun sql-highlight-sybase-keywords ()
1778 "Highlight Sybase SQL keywords."
1779 (interactive)
1780 (sql-set-product 'sybase))
1781
1782(defun sql-highlight-informix-keywords ()
1783 "Highlight Informix SQL keywords."
1784 (interactive)
1785 (sql-set-product 'informix))
1786
1787(defun sql-highlight-interbase-keywords ()
1788 "Highlight Interbase SQL keywords."
1789 (interactive)
1790 (sql-set-product 'interbase))
1791
1792(defun sql-highlight-ingres-keywords ()
1793 "Highlight Ingres SQL keywords."
1794 (interactive)
1795 (sql-set-product 'ingres))
1796
1797(defun sql-highlight-solid-keywords ()
1798 "Highlight Solid SQL keywords."
1799 (interactive)
1800 (sql-set-product 'solid))
1801
1802(defun sql-highlight-mysql-keywords ()
1803 "Highlight MySQL SQL keywords."
1804 (interactive)
1805 (sql-set-product 'mysql))
1806
1807(defun sql-highlight-sqlite-keywords ()
1808 "Highlight SQLite SQL keywords."
1809 (interactive)
1810 (sql-set-product 'sqlite))
1811
1812(defun sql-highlight-db2-keywords ()
1813 "Highlight DB2 SQL keywords."
1814 (interactive)
1815 (sql-set-product 'db2))
624ef9b3
GM
1816
1817\f
1818
04231ab8
MB
1819;;; Compatibility functions
1820
1821(if (not (fboundp 'comint-line-beginning-position))
1822 ;; comint-line-beginning-position is defined in Emacs 21
1823 (defun comint-line-beginning-position ()
1824 "Returns the buffer position of the beginning of the line, after any prompt.
1825The prompt is assumed to be any text at the beginning of the line matching
1826the regular expression `comint-prompt-regexp', a buffer local variable."
1827 (save-excursion (comint-bol nil) (point))))
1828
1829\f
95e4b2ef
RS
1830
1831;;; Small functions
1832
9ef3882f
GM
1833(defun sql-magic-go (arg)
1834 "Insert \"o\" and call `comint-send-input'.
1835`sql-electric-stuff' must be the symbol `go'."
1836 (interactive "P")
1837 (self-insert-command (prefix-numeric-value arg))
1838 (if (and (equal sql-electric-stuff 'go)
1839 (save-excursion
3035b156
MB
1840 (comint-bol nil)
1841 (looking-at "go\\b")))
9ef3882f
GM
1842 (comint-send-input)))
1843
1844(defun sql-magic-semicolon (arg)
1845 "Insert semicolon and call `comint-send-input'.
1846`sql-electric-stuff' must be the symbol `semicolon'."
1847 (interactive "P")
1848 (self-insert-command (prefix-numeric-value arg))
1849 (if (equal sql-electric-stuff 'semicolon)
1850 (comint-send-input)))
1851
95e4b2ef
RS
1852(defun sql-accumulate-and-indent ()
1853 "Continue SQL statement on the next line."
1854 (interactive)
f4df536d 1855 (if (fboundp 'comint-accumulate)
9ef3882f
GM
1856 (comint-accumulate)
1857 (newline))
95e4b2ef
RS
1858 (indent-according-to-mode))
1859
1860;;;###autoload
1861(defun sql-help ()
801d1cb0 1862 "Show short help for the SQL modes.
95e4b2ef
RS
1863
1864Use an entry function to open an interactive SQL buffer. This buffer is
dab100d7 1865usually named `*SQL*'. The name of the major mode is SQLi.
95e4b2ef
RS
1866
1867Use the following commands to start a specific SQL interpreter:
1868
dab100d7 1869 PostGres: \\[sql-postgres]
058fb10a 1870 MySQL: \\[sql-mysql]
5d538ce3 1871 SQLite: \\[sql-sqlite]
50842164
RS
1872
1873Other non-free SQL implementations are also supported:
1874
dab100d7
RS
1875 Solid: \\[sql-solid]
1876 Oracle: \\[sql-oracle]
1877 Informix: \\[sql-informix]
50842164
RS
1878 Sybase: \\[sql-sybase]
1879 Ingres: \\[sql-ingres]
1880 Microsoft: \\[sql-ms]
78024f88 1881 DB2: \\[sql-db2]
624ef9b3 1882 Interbase: \\[sql-interbase]
f4df536d 1883 Linter: \\[sql-linter]
50842164
RS
1884
1885But we urge you to choose a free implementation instead of these.
95e4b2ef
RS
1886
1887Once you have the SQLi buffer, you can enter SQL statements in the
1888buffer. The output generated is appended to the buffer and a new prompt
1889is generated. See the In/Out menu in the SQLi buffer for some functions
1890that help you navigate through the buffer, the input history, etc.
1891
95e4b2ef
RS
1892If you have a really complex SQL statement or if you are writing a
1893procedure, you can do this in a separate buffer. Put the new buffer in
1894`sql-mode' by calling \\[sql-mode]. The name of this buffer can be
1895anything. The name of the major mode is SQL.
1896
1897In this SQL buffer (SQL mode), you can send the region or the entire
1898buffer to the interactive SQL buffer (SQLi mode). The results are
1899appended to the SQLi buffer without disturbing your SQL buffer."
1900 (interactive)
1901 (describe-function 'sql-help))
1902
1903(defun sql-read-passwd (prompt &optional default)
1904 "Read a password using PROMPT.
1905Optional DEFAULT is password to start with. This function calls
1906`read-passwd' if it is available. If not, function
1907`ange-ftp-read-passwd' is called. This should always be available,
1908even in old versions of Emacs."
1909 (if (fboundp 'read-passwd)
1910 (read-passwd prompt nil default)
1911 (unless (fboundp 'ange-ftp-read-passwd)
1912 (autoload 'ange-ftp-read-passwd "ange-ftp"))
1913 (ange-ftp-read-passwd prompt default)))
1914
1915(defun sql-get-login (&rest what)
1916 "Get username, password and database from the user.
1917
dab100d7 1918The variables `sql-user', `sql-password', `sql-server', and
eb3f61dd 1919`sql-database' can be customized. They are used as the default values.
dab100d7
RS
1920Usernames, servers and databases are stored in `sql-user-history',
1921`sql-server-history' and `database-history'. Passwords are not stored
1922in a history.
95e4b2ef
RS
1923
1924Parameter WHAT is a list of the arguments passed to this function.
1925The function asks for the username if WHAT contains symbol `user', for
1926the password if it contains symbol `password', for the server if it
1927contains symbol `server', and for the database if it contains symbol
78024f88
AS
1928`database'. The members of WHAT are processed in the order in which
1929they are provided.
95e4b2ef
RS
1930
1931In order to ask the user for username, password and database, call the
1932function like this: (sql-get-login 'user 'password 'database)."
1933 (interactive)
78024f88
AS
1934 (while what
1935 (cond
1936 ((eq (car what) 'user) ; user
801d1cb0 1937 (setq sql-user
95e4b2ef
RS
1938 (read-from-minibuffer "User: " sql-user nil nil
1939 sql-user-history)))
78024f88 1940 ((eq (car what) 'password) ; password
801d1cb0 1941 (setq sql-password
95e4b2ef 1942 (sql-read-passwd "Password: " sql-password)))
78024f88 1943 ((eq (car what) 'server) ; server
801d1cb0 1944 (setq sql-server
95e4b2ef
RS
1945 (read-from-minibuffer "Server: " sql-server nil nil
1946 sql-server-history)))
78024f88 1947 ((eq (car what) 'database) ; database
801d1cb0 1948 (setq sql-database
95e4b2ef
RS
1949 (read-from-minibuffer "Database: " sql-database nil nil
1950 sql-database-history))))
78024f88 1951 (setq what (cdr what))))
1533eb58 1952
46d94d0d
GM
1953(defun sql-find-sqli-buffer ()
1954 "Return the current default SQLi buffer or nil.
1955In order to qualify, the SQLi buffer must be alive,
1956be in `sql-interactive-mode' and have a process."
9ef3882f
GM
1957 (let ((default-buffer (default-value 'sql-buffer)))
1958 (if (and (buffer-live-p default-buffer)
1959 (get-buffer-process default-buffer))
1960 default-buffer
1961 (save-excursion
1962 (let ((buflist (buffer-list))
1963 (found))
1964 (while (not (or (null buflist)
1965 found))
1966 (let ((candidate (car buflist)))
1967 (set-buffer candidate)
1968 (if (and (equal major-mode 'sql-interactive-mode)
1969 (get-buffer-process candidate))
1970 (setq found candidate))
1971 (setq buflist (cdr buflist))))
1972 found)))))
46d94d0d
GM
1973
1974(defun sql-set-sqli-buffer-generally ()
f4df536d 1975 "Set SQLi buffer for all SQL buffers that have none.
46d94d0d
GM
1976This function checks all SQL buffers for their SQLi buffer. If their
1977SQLi buffer is nonexistent or has no process, it is set to the current
1978default SQLi buffer. The current default SQLi buffer is determined
1979using `sql-find-sqli-buffer'. If `sql-buffer' is set,
1980`sql-set-sqli-hook' is run."
1981 (interactive)
1982 (save-excursion
1983 (let ((buflist (buffer-list))
1984 (default-sqli-buffer (sql-find-sqli-buffer)))
1985 (setq-default sql-buffer default-sqli-buffer)
1986 (while (not (null buflist))
1987 (let ((candidate (car buflist)))
1988 (set-buffer candidate)
1989 (if (and (equal major-mode 'sql-mode)
1990 (not (buffer-live-p sql-buffer)))
1991 (progn
1992 (setq sql-buffer default-sqli-buffer)
1993 (run-hooks 'sql-set-sqli-hook))))
1994 (setq buflist (cdr buflist))))))
1995
c7055d66
RS
1996(defun sql-set-sqli-buffer ()
1997 "Set the SQLi buffer SQL strings are sent to.
95e4b2ef 1998
c7055d66
RS
1999Call this function in a SQL buffer in order to set the SQLi buffer SQL
2000strings are sent to. Calling this function sets `sql-buffer' and runs
2001`sql-set-sqli-hook'.
dab100d7 2002
c7055d66 2003If you call it from a SQL buffer, this sets the local copy of
801d1cb0 2004`sql-buffer'.
dab100d7 2005
c7055d66 2006If you call it from anywhere else, it sets the global copy of
dab100d7
RS
2007`sql-buffer'."
2008 (interactive)
46d94d0d
GM
2009 (let ((default-buffer (sql-find-sqli-buffer)))
2010 (if (null default-buffer)
2011 (error "There is no suitable SQLi buffer"))
2012 (let ((new-buffer
2013 (get-buffer
2014 (read-buffer "New SQLi buffer: " default-buffer t))))
2015 (if (null (get-buffer-process new-buffer))
2016 (error "Buffer %s has no process" (buffer-name new-buffer)))
2017 (if (null (save-excursion
2018 (set-buffer new-buffer)
2019 (equal major-mode 'sql-interactive-mode)))
2020 (error "Buffer %s is no SQLi buffer" (buffer-name new-buffer)))
2021 (if new-buffer
2022 (progn
2023 (setq sql-buffer new-buffer)
2024 (run-hooks 'sql-set-sqli-hook))))))
dab100d7
RS
2025
2026(defun sql-show-sqli-buffer ()
2027 "Show the name of current SQLi buffer.
2028
2029This is the buffer SQL strings are sent to. It is stored in the
2030variable `sql-buffer'. See `sql-help' on how to create such a buffer."
2031 (interactive)
2032 (if (null (buffer-live-p sql-buffer))
c7055d66 2033 (message "%s has no SQLi buffer set." (buffer-name (current-buffer)))
dab100d7
RS
2034 (if (null (get-buffer-process sql-buffer))
2035 (message "Buffer %s has no process." (buffer-name sql-buffer))
2036 (message "Current SQLi buffer is %s." (buffer-name sql-buffer)))))
2037
c7055d66
RS
2038(defun sql-make-alternate-buffer-name ()
2039 "Return a string that can be used to rename a SQLi buffer.
2040
2041This is used to set `sql-alternate-buffer-name' within
2042`sql-interactive-mode'."
2043 (concat (if (string= "" sql-user)
9ef3882f 2044 (if (string= "" (user-login-name))
c7055d66 2045 ()
9ef3882f 2046 (concat (user-login-name) "/"))
c7055d66
RS
2047 (concat sql-user "/"))
2048 (if (string= "" sql-database)
2049 (if (string= "" sql-server)
9ef3882f 2050 (system-name)
c7055d66
RS
2051 sql-server)
2052 sql-database)))
2053
2054(defun sql-rename-buffer ()
2055 "Renames a SQLi buffer."
2056 (interactive)
2057 (rename-buffer (format "*SQL: %s*" sql-alternate-buffer-name) t))
2058
95e4b2ef
RS
2059(defun sql-copy-column ()
2060 "Copy current column to the end of buffer.
2061Inserts SELECT or commas if appropriate."
2062 (interactive)
2063 (let ((column))
2064 (save-excursion
2065 (setq column (buffer-substring
2066 (progn (forward-char 1) (backward-sexp 1) (point))
2067 (progn (forward-sexp 1) (point))))
2068 (goto-char (point-max))
3035b156
MB
2069 (let ((bol (comint-line-beginning-position)))
2070 (cond
2071 ;; if empty command line, insert SELECT
2072 ((= bol (point))
2073 (insert "SELECT "))
2074 ;; else if appending to INTO .* (, SELECT or ORDER BY, insert a comma
2075 ((save-excursion
2076 (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+"
2077 bol t))
2078 (insert ", "))
2079 ;; else insert a space
2080 (t
b9584f65 2081 (if (eq (preceding-char) ?\s)
3035b156
MB
2082 nil
2083 (insert " ")))))
95e4b2ef
RS
2084 ;; in any case, insert the column
2085 (insert column)
2086 (message "%s" column))))
2087
77d352a6
GM
2088;; On NT, SQL*Plus for Oracle turns on full buffering for stdout if it
2089;; is not attached to a character device; therefore placeholder
2090;; replacement by SQL*Plus is fully buffered. The workaround lets
2091;; Emacs query for the placeholders.
2092
2093(defvar sql-placeholder-history nil
2094 "History of placeholder values used.")
2095
2096(defun sql-query-placeholders-and-send (proc string)
2097 "Send to PROC input STRING, maybe replacing placeholders.
2098Placeholders are words starting with and ampersand like &this.
2099This function is used for `comint-input-sender' if using `sql-oracle' on NT."
2100 (while (string-match "&\\(\\sw+\\)" string)
f4df536d 2101 (setq string (replace-match
77d352a6
GM
2102 (read-from-minibuffer
2103 (format "Enter value for %s: " (match-string 1 string))
2104 nil nil nil sql-placeholder-history)
2105 t t string)))
2106 (comint-send-string proc string)
60a193e2 2107 (if comint-input-sender-no-newline
754dfe82 2108 (if (not (string-equal string ""))
60a193e2
RS
2109 (process-send-eof))
2110 (comint-send-string proc "\n")))
77d352a6 2111
624ef9b3
GM
2112;; Using DB2 interactively, newlines must be escaped with " \".
2113;; The space before the backslash is relevant.
2114(defun sql-escape-newlines-and-send (proc string)
2115 "Send to PROC input STRING, escaping newlines if necessary.
2116Every newline in STRING will be preceded with a space and a backslash."
2117 (let ((result "") (start 0) mb me)
2118 (while (string-match "\n" string start)
2119 (setq mb (match-beginning 0)
2120 me (match-end 0))
2121 (if (and (> mb 1)
2122 (string-equal " \\" (substring string (- mb 2) mb)))
2123 (setq result (concat result (substring string start me)))
2124 (setq result (concat result (substring string start mb) " \\\n")))
2125 (setq start me))
2126 (setq result (concat result (substring string start)))
2127 (comint-send-string proc result)
60a193e2 2128 (if comint-input-sender-no-newline
754dfe82 2129 (if (not (string-equal string ""))
60a193e2
RS
2130 (process-send-eof))
2131 (comint-send-string proc "\n"))))
624ef9b3 2132
95e4b2ef
RS
2133\f
2134
2135;;; Sending the region to the SQLi buffer.
2136
2137(defun sql-send-region (start end)
2138 "Send a region to the SQL process."
2139 (interactive "r")
2140 (if (buffer-live-p sql-buffer)
2141 (save-excursion
2142 (comint-send-region sql-buffer start end)
2143 (if (string-match "\n$" (buffer-substring start end))
2144 ()
2145 (comint-send-string sql-buffer "\n"))
a081a529 2146 (message "Sent string to buffer %s." (buffer-name sql-buffer))
801d1cb0 2147 (if sql-pop-to-buffer-after-send-region
95e4b2ef
RS
2148 (pop-to-buffer sql-buffer)
2149 (display-buffer sql-buffer)))
2150 (message "No SQL process started.")))
2151
dab100d7
RS
2152(defun sql-send-paragraph ()
2153 "Send the current paragraph to the SQL process."
2154 (interactive)
2155 (let ((start (save-excursion
2156 (backward-paragraph)
2157 (point)))
2158 (end (save-excursion
2159 (forward-paragraph)
2160 (point))))
2161 (sql-send-region start end)))
2162
95e4b2ef
RS
2163(defun sql-send-buffer ()
2164 "Send the buffer contents to the SQL process."
2165 (interactive)
2166 (sql-send-region (point-min) (point-max)))
2167
9fd8cb36
SM
2168(defun sql-send-string (str)
2169 "Send a string to the SQL process."
2170 (interactive "sSQL Text: ")
2171 (if (buffer-live-p sql-buffer)
2172 (save-excursion
2173 (comint-send-string sql-buffer str)
2174 (comint-send-string sql-buffer "\n")
2175 (message "Sent string to buffer %s." (buffer-name sql-buffer))
2176 (if sql-pop-to-buffer-after-send-region
2177 (pop-to-buffer sql-buffer)
2178 (display-buffer sql-buffer)))
2179 (message "No SQL process started.")))
2180
95e4b2ef
RS
2181(defun sql-toggle-pop-to-buffer-after-send-region (&optional value)
2182 "Toggle `sql-pop-to-buffer-after-send-region'.
2183
2184If given the optional parameter VALUE, sets
2185sql-toggle-pop-to-buffer-after-send-region to VALUE."
2186 (interactive "P")
2187 (if value
2188 (setq sql-pop-to-buffer-after-send-region value)
801d1cb0 2189 (setq sql-pop-to-buffer-after-send-region
95e4b2ef
RS
2190 (null sql-pop-to-buffer-after-send-region ))))
2191
2192\f
2193
2194;;; SQL mode -- uses SQL interactive mode
2195
2196;;;###autoload
2197(defun sql-mode ()
2198 "Major mode to edit SQL.
2199
dab100d7 2200You can send SQL statements to the SQLi buffer using
95e4b2ef 2201\\[sql-send-region]. Such a buffer must exist before you can do this.
dab100d7 2202See `sql-help' on how to create SQLi buffers.
95e4b2ef 2203
801d1cb0 2204\\{sql-mode-map}
95e4b2ef
RS
2205Customization: Entry to this mode runs the `sql-mode-hook'.
2206
dab100d7
RS
2207When you put a buffer in SQL mode, the buffer stores the last SQLi
2208buffer created as its destination in the variable `sql-buffer'. This
2209will be the buffer \\[sql-send-region] sends the region to. If this
2210SQLi buffer is killed, \\[sql-send-region] is no longer able to
c7055d66
RS
2211determine where the strings should be sent to. You can set the
2212value of `sql-buffer' using \\[sql-set-sqli-buffer].
95e4b2ef 2213
dab100d7 2214For information on how to create multiple SQLi buffers, see
4da8ff79
RS
2215`sql-interactive-mode'.
2216
2217Note that SQL doesn't have an escape character unless you specify
2218one. If you specify backslash as escape character in SQL,
2219you must tell Emacs. Here's how to do that in your `~/.emacs' file:
2220
2221\(add-hook 'sql-mode-hook
2222 (lambda ()
2223 (modify-syntax-entry ?\\\\ \".\" sql-mode-syntax-table)))"
95e4b2ef
RS
2224 (interactive)
2225 (kill-all-local-variables)
2226 (setq major-mode 'sql-mode)
2227 (setq mode-name "SQL")
2228 (use-local-map sql-mode-map)
311e7a89
GM
2229 (if sql-mode-menu
2230 (easy-menu-add sql-mode-menu)); XEmacs
95e4b2ef
RS
2231 (set-syntax-table sql-mode-syntax-table)
2232 (make-local-variable 'font-lock-defaults)
78024f88 2233 (make-local-variable 'sql-mode-font-lock-keywords)
a081a529
RS
2234 (make-local-variable 'comment-start)
2235 (setq comment-start "--")
801d1cb0 2236 ;; Make each buffer in sql-mode remember the "current" SQLi buffer.
dab100d7 2237 (make-local-variable 'sql-buffer)
801d1cb0
AS
2238 ;; Add imenu support for sql-mode. Note that imenu-generic-expression
2239 ;; is buffer-local, so we don't need a local-variable for it. SQL is
2240 ;; case-insensitive, that's why we have to set imenu-case-fold-search.
801d1cb0 2241 (setq imenu-generic-expression sql-imenu-generic-expression
78024f88 2242 imenu-case-fold-search t)
c7055d66
RS
2243 ;; Make `sql-send-paragraph' work on paragraphs that contain indented
2244 ;; lines.
2245 (make-local-variable 'paragraph-separate)
2246 (make-local-variable 'paragraph-start)
2247 (setq paragraph-separate "[\f]*$"
2248 paragraph-start "[\n\f]")
801d1cb0 2249 ;; Abbrevs
95e4b2ef
RS
2250 (setq local-abbrev-table sql-mode-abbrev-table)
2251 (setq abbrev-all-caps 1)
801d1cb0 2252 ;; Run hook
9a969196 2253 (run-mode-hooks 'sql-mode-hook)
78024f88
AS
2254 ;; Catch changes to sql-product and highlight accordingly
2255 (sql-highlight-product)
2256 (add-hook 'hack-local-variables-hook 'sql-highlight-product t t))
95e4b2ef
RS
2257
2258\f
2259
2260;;; SQL interactive mode
2261
2262(put 'sql-interactive-mode 'mode-class 'special)
2263
2264(defun sql-interactive-mode ()
2265 "Major mode to use a SQL interpreter interactively.
2266
2267Do not call this function by yourself. The environment must be
2268initialized by an entry function specific for the SQL interpreter. See
2269`sql-help' for a list of available entry functions.
2270
2271\\[comint-send-input] after the end of the process' output sends the
2272text from the end of process to the end of the current line.
2273\\[comint-send-input] before end of process output copies the current
2274line minus the prompt to the end of the buffer and sends it.
2275\\[comint-copy-old-input] just copies the current line.
2276Use \\[sql-accumulate-and-indent] to enter multi-line statements.
2277
2278If you want to make multiple SQL buffers, rename the `*SQL*' buffer
2279using \\[rename-buffer] or \\[rename-uniquely] and start a new process.
dab100d7
RS
2280See `sql-help' for a list of available entry functions. The last buffer
2281created by such an entry function is the current SQLi buffer. SQL
2282buffers will send strings to the SQLi buffer current at the time of
2283their creation. See `sql-mode' for details.
2284
2285Sample session using two connections:
2286
22871. Create first SQLi buffer by calling an entry function.
22882. Rename buffer \"*SQL*\" to \"*Connection 1*\".
22893. Create a SQL buffer \"test1.sql\".
22904. Create second SQLi buffer by calling an entry function.
22915. Rename buffer \"*SQL*\" to \"*Connection 2*\".
22926. Create a SQL buffer \"test2.sql\".
2293
2294Now \\[sql-send-region] in buffer \"test1.sql\" will send the region to
2295buffer \"*Connection 1*\", \\[sql-send-region] in buffer \"test2.sql\"
2296will send the region to buffer \"*Connection 2*\".
95e4b2ef
RS
2297
2298If you accidentally suspend your process, use \\[comint-continue-subjob]
dab100d7
RS
2299to continue it. On some operating systems, this will not work because
2300the signals are not supported.
95e4b2ef
RS
2301
2302\\{sql-interactive-mode-map}
2303Customization: Entry to this mode runs the hooks on `comint-mode-hook'
2304and `sql-interactive-mode-hook' (in that order). Before each input, the
2305hooks on `comint-input-filter-functions' are run. After each SQL
2306interpreter output, the hooks on `comint-output-filter-functions' are
2307run.
2308
c7055d66 2309Variable `sql-input-ring-file-name' controls the initialisation of the
77d352a6 2310input ring history.
95e4b2ef
RS
2311
2312Variables `comint-output-filter-functions', a hook, and
2313`comint-scroll-to-bottom-on-input' and
2314`comint-scroll-to-bottom-on-output' control whether input and output
2315cause the window to scroll to the end of the buffer.
2316
2317If you want to make SQL buffers limited in length, add the function
2318`comint-truncate-buffer' to `comint-output-filter-functions'.
2319
dab100d7 2320Here is an example for your .emacs file. It keeps the SQLi buffer a
c7055d66 2321certain length.
95e4b2ef
RS
2322
2323\(add-hook 'sql-interactive-mode-hook
2324 \(function (lambda ()
95e4b2ef
RS
2325 \(setq comint-output-filter-functions 'comint-truncate-buffer))))
2326
2327Here is another example. It will always put point back to the statement
2328you entered, right above the output it created.
2329
801d1cb0 2330\(setq comint-output-filter-functions
95e4b2ef 2331 \(function (lambda (STR) (comint-show-output))))"
03789b21 2332 (delay-mode-hooks (comint-mode))
78024f88
AS
2333 ;; Get the `sql-product' for this interactive session.
2334 (set (make-local-variable 'sql-product)
2335 (or sql-interactive-product
2336 sql-product))
2337 ;; Setup the mode.
95e4b2ef 2338 (setq major-mode 'sql-interactive-mode)
78024f88 2339 (setq mode-name (concat "SQLi[" (prin1-to-string sql-product) "]"))
95e4b2ef 2340 (use-local-map sql-interactive-mode-map)
311e7a89 2341 (if sql-interactive-mode-menu
78024f88 2342 (easy-menu-add sql-interactive-mode-menu)) ; XEmacs
95e4b2ef 2343 (set-syntax-table sql-mode-syntax-table)
78024f88 2344 (make-local-variable 'sql-mode-font-lock-keywords)
95e4b2ef 2345 (make-local-variable 'font-lock-defaults)
a081a529 2346 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
801d1cb0
AS
2347 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
2348 ;; will have just one quote. Therefore syntactic hilighting is
78024f88
AS
2349 ;; disabled for interactive buffers. No imenu support.
2350 (sql-product-font-lock t nil)
c7055d66 2351 ;; Enable commenting and uncommenting of the region.
a081a529
RS
2352 (make-local-variable 'comment-start)
2353 (setq comment-start "--")
78024f88 2354 ;; Abbreviation table init and case-insensitive. It is not activated
c7055d66 2355 ;; by default.
95e4b2ef
RS
2356 (setq local-abbrev-table sql-mode-abbrev-table)
2357 (setq abbrev-all-caps 1)
c7055d66 2358 ;; Exiting the process will call sql-stop.
95e4b2ef 2359 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop)
78024f88
AS
2360 ;; Create a usefull name for renaming this buffer later.
2361 (make-local-variable 'sql-alternate-buffer-name)
2362 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name))
2363 ;; User stuff. Initialize before the hook.
2364 (set (make-local-variable 'sql-prompt-regexp)
2365 (sql-product-feature :sqli-prompt-regexp))
2366 (set (make-local-variable 'sql-prompt-length)
2367 (sql-product-feature :sqli-prompt-length))
2368 (make-local-variable 'sql-input-ring-separator)
2369 (make-local-variable 'sql-input-ring-file-name)
2370 ;; Run hook.
9a969196 2371 (run-mode-hooks 'sql-interactive-mode-hook)
78024f88
AS
2372 ;; Set comint based on user overrides.
2373 (setq comint-prompt-regexp sql-prompt-regexp)
2374 (setq left-margin sql-prompt-length)
77d352a6
GM
2375 ;; People wanting a different history file for each
2376 ;; buffer/process/client/whatever can change separator and file-name
2377 ;; on the sql-interactive-mode-hook.
2378 (setq comint-input-ring-separator sql-input-ring-separator
2379 comint-input-ring-file-name sql-input-ring-file-name)
c7055d66 2380 ;; Calling the hook before calling comint-read-input-ring allows users
95e4b2ef 2381 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook.
77d352a6 2382 (comint-read-input-ring t))
95e4b2ef
RS
2383
2384(defun sql-stop (process event)
2385 "Called when the SQL process is stopped.
2386
c7055d66
RS
2387Writes the input history to a history file using
2388`comint-write-input-ring' and inserts a short message in the SQL buffer.
95e4b2ef
RS
2389
2390This function is a sentinel watching the SQL interpreter process.
2391Sentinels will always get the two parameters PROCESS and EVENT."
77d352a6
GM
2392 (comint-write-input-ring)
2393 (if (and (eq (current-buffer) sql-buffer)
2394 (not buffer-read-only))
2395 (insert (format "\nProcess %s %s\n" process event))
2396 (message "Process %s %s" process event)))
95e4b2ef
RS
2397
2398\f
2399
2400;;; Entry functions for different SQL interpreters.
2401
78024f88
AS
2402;;;###autoload
2403(defun sql-product-interactive (&optional product)
2404 "Run product interpreter as an inferior process.
2405
2406If buffer `*SQL*' exists but no process is running, make a new process.
2407If buffer exists and a process is running, just switch to buffer
2408`*SQL*'.
2409
2410\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2411 (interactive)
2412 (setq product (or product sql-product))
2413 (when (sql-product-feature :sqli-connect product)
2414 (if (comint-check-proc "*SQL*")
2415 (pop-to-buffer "*SQL*")
2416 ;; Get credentials.
2417 (apply 'sql-get-login (sql-product-feature :sqli-login product))
2418 ;; Connect to database.
2419 (message "Login...")
2420 (funcall (sql-product-feature :sqli-connect product))
2421 ;; Set SQLi mode.
2422 (setq sql-interactive-product product)
2423 (setq sql-buffer (current-buffer))
2424 (sql-interactive-mode)
2425 ;; All done.
2426 (message "Login...done")
2427 (pop-to-buffer sql-buffer))))
2428
77d352a6 2429;;;###autoload
95e4b2ef
RS
2430(defun sql-oracle ()
2431 "Run sqlplus by Oracle as an inferior process.
2432
dab100d7 2433If buffer `*SQL*' exists but no process is running, make a new process.
95e4b2ef
RS
2434If buffer exists and a process is running, just switch to buffer
2435`*SQL*'.
2436
dab100d7
RS
2437Interpreter used comes from variable `sql-oracle-program'. Login uses
2438the variables `sql-user', `sql-password', and `sql-database' as
9ef3882f
GM
2439defaults, if set. Additional command line parameters can be stored in
2440the list `sql-oracle-options'.
95e4b2ef
RS
2441
2442The buffer is put in sql-interactive-mode, giving commands for sending
2443input. See `sql-interactive-mode'.
2444
2445To specify a coding system for converting non-ASCII characters
2446in the input and output to the process, use \\[universal-coding-system-argument]
2447before \\[sql-oracle]. You can also specify this with \\[set-buffer-process-coding-system]
2448in the SQL buffer, after you start the process.
2449The default comes from `process-coding-system-alist' and
2450`default-process-coding-system'.
2451
2452\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2453 (interactive)
78024f88
AS
2454 (sql-product-interactive 'oracle))
2455
2456(defun sql-connect-oracle ()
2457 "Create comint buffer and connect to Oracle using the login
2458parameters and command options."
2459 ;; Produce user/password@database construct. Password without user
2460 ;; is meaningless; database without user/password is meaningless,
2461 ;; because "@param" will ask sqlplus to interpret the script
2462 ;; "param".
2463 (let ((parameter nil))
2464 (if (not (string= "" sql-user))
2465 (if (not (string= "" sql-password))
2466 (setq parameter (concat sql-user "/" sql-password))
2467 (setq parameter sql-user)))
2468 (if (and parameter (not (string= "" sql-database)))
2469 (setq parameter (concat parameter "@" sql-database)))
2470 (if parameter
2471 (setq parameter (nconc (list parameter) sql-oracle-options))
2472 (setq parameter sql-oracle-options))
2473 (if parameter
2474 (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil
2475 parameter))
2476 (set-buffer (make-comint "SQL" sql-oracle-program nil)))
2477 ;; SQL*Plus is buffered on WindowsNT; this handles &placeholders.
77d352a6 2478 (if (eq window-system 'w32)
78024f88 2479 (setq comint-input-sender 'sql-query-placeholders-and-send))))
95e4b2ef
RS
2480
2481\f
2482
77d352a6 2483;;;###autoload
95e4b2ef
RS
2484(defun sql-sybase ()
2485 "Run isql by SyBase as an inferior process.
2486
dab100d7 2487If buffer `*SQL*' exists but no process is running, make a new process.
95e4b2ef
RS
2488If buffer exists and a process is running, just switch to buffer
2489`*SQL*'.
2490
2491Interpreter used comes from variable `sql-sybase-program'. Login uses
9b5360aa 2492the variables `sql-server', `sql-user', `sql-password', and
7a65c85c
GM
2493`sql-database' as defaults, if set. Additional command line parameters
2494can be stored in the list `sql-sybase-options'.
95e4b2ef
RS
2495
2496The buffer is put in sql-interactive-mode, giving commands for sending
2497input. See `sql-interactive-mode'.
2498
2499To specify a coding system for converting non-ASCII characters
2500in the input and output to the process, use \\[universal-coding-system-argument]
2501before \\[sql-sybase]. You can also specify this with \\[set-buffer-process-coding-system]
2502in the SQL buffer, after you start the process.
2503The default comes from `process-coding-system-alist' and
2504`default-process-coding-system'.
2505
2506\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2507 (interactive)
78024f88
AS
2508 (sql-product-interactive 'sybase))
2509
2510(defun sql-connect-sybase ()
2511 "Create comint buffer and connect to Sybase using the login
2512parameters and command options."
2513 ;; Put all parameters to the program (if defined) in a list and call
2514 ;; make-comint.
2515 (let ((params sql-sybase-options))
2516 (if (not (string= "" sql-server))
2517 (setq params (append (list "-S" sql-server) params)))
2518 (if (not (string= "" sql-database))
2519 (setq params (append (list "-D" sql-database) params)))
2520 (if (not (string= "" sql-password))
2521 (setq params (append (list "-P" sql-password) params)))
2522 (if (not (string= "" sql-user))
2523 (setq params (append (list "-U" sql-user) params)))
2524 (set-buffer (apply 'make-comint "SQL" sql-sybase-program
2525 nil params))))
95e4b2ef
RS
2526
2527\f
2528
77d352a6 2529;;;###autoload
95e4b2ef
RS
2530(defun sql-informix ()
2531 "Run dbaccess by Informix as an inferior process.
2532
dab100d7 2533If buffer `*SQL*' exists but no process is running, make a new process.
95e4b2ef
RS
2534If buffer exists and a process is running, just switch to buffer
2535`*SQL*'.
2536
2537Interpreter used comes from variable `sql-informix-program'. Login uses
2538the variable `sql-database' as default, if set.
2539
2540The buffer is put in sql-interactive-mode, giving commands for sending
2541input. See `sql-interactive-mode'.
2542
2543To specify a coding system for converting non-ASCII characters
2544in the input and output to the process, use \\[universal-coding-system-argument]
2545before \\[sql-informix]. You can also specify this with \\[set-buffer-process-coding-system]
2546in the SQL buffer, after you start the process.
2547The default comes from `process-coding-system-alist' and
2548`default-process-coding-system'.
2549
2550\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2551 (interactive)
78024f88
AS
2552 (sql-product-interactive 'informix))
2553
2554(defun sql-connect-informix ()
2555 "Create comint buffer and connect to Informix using the login
2556parameters and command options."
2557 ;; username and password are ignored.
2558 (if (string= "" sql-database)
2559 (set-buffer (make-comint "SQL" sql-informix-program nil))
2560 (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-"))))
a081a529
RS
2561
2562\f
2563
5d538ce3
JB
2564;;;###autoload
2565(defun sql-sqlite ()
2566 "Run sqlite as an inferior process.
2567
2568SQLite is free software.
2569
2570If buffer `*SQL*' exists but no process is running, make a new process.
2571If buffer exists and a process is running, just switch to buffer
2572`*SQL*'.
2573
2574Interpreter used comes from variable `sql-sqlite-program'. Login uses
2575the variables `sql-user', `sql-password', `sql-database', and
2576`sql-server' as defaults, if set. Additional command line parameters
2577can be stored in the list `sql-sqlite-options'.
2578
2579The buffer is put in sql-interactive-mode, giving commands for sending
2580input. See `sql-interactive-mode'.
2581
2582To specify a coding system for converting non-ASCII characters
2583in the input and output to the process, use \\[universal-coding-system-argument]
2584before \\[sql-sqlite]. You can also specify this with \\[set-buffer-process-coding-system]
2585in the SQL buffer, after you start the process.
2586The default comes from `process-coding-system-alist' and
2587`default-process-coding-system'.
2588
2589\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2590 (interactive)
78024f88
AS
2591 (sql-product-interactive 'sqlite))
2592
2593(defun sql-connect-sqlite ()
2594 "Create comint buffer and connect to SQLite using the login
2595parameters and command options."
2596 ;; Put all parameters to the program (if defined) in a list and call
2597 ;; make-comint.
2598 (let ((params))
2599 (if (not (string= "" sql-database))
2600 (setq params (append (list sql-database) params)))
2601 (if (not (string= "" sql-server))
2602 (setq params (append (list (concat "--host=" sql-server)) params)))
2603 (if (not (string= "" sql-password))
2604 (setq params (append (list (concat "--password=" sql-password)) params)))
2605 (if (not (string= "" sql-user))
2606 (setq params (append (list (concat "--user=" sql-user)) params)))
2607 (if (not (null sql-sqlite-options))
2608 (setq params (append sql-sqlite-options params)))
2609 (set-buffer (apply 'make-comint "SQL" sql-sqlite-program
2610 nil params))))
5d538ce3
JB
2611
2612\f
2613
77d352a6 2614;;;###autoload
a081a529
RS
2615(defun sql-mysql ()
2616 "Run mysql by TcX as an inferior process.
dab100d7 2617
058fb10a 2618Mysql versions 3.23 and up are free software.
a081a529 2619
50842164 2620If buffer `*SQL*' exists but no process is running, make a new process.
a081a529
RS
2621If buffer exists and a process is running, just switch to buffer
2622`*SQL*'.
2623
2624Interpreter used comes from variable `sql-mysql-program'. Login uses
dab100d7 2625the variables `sql-user', `sql-password', `sql-database', and
7a65c85c
GM
2626`sql-server' as defaults, if set. Additional command line parameters
2627can be stored in the list `sql-mysql-options'.
a081a529
RS
2628
2629The buffer is put in sql-interactive-mode, giving commands for sending
2630input. See `sql-interactive-mode'.
2631
2632To specify a coding system for converting non-ASCII characters
2633in the input and output to the process, use \\[universal-coding-system-argument]
dab100d7 2634before \\[sql-mysql]. You can also specify this with \\[set-buffer-process-coding-system]
a081a529
RS
2635in the SQL buffer, after you start the process.
2636The default comes from `process-coding-system-alist' and
2637`default-process-coding-system'.
2638
2639\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2640 (interactive)
78024f88
AS
2641 (sql-product-interactive 'mysql))
2642
2643(defun sql-connect-mysql ()
2644 "Create comint buffer and connect to MySQL using the login
2645parameters and command options."
2646 ;; Put all parameters to the program (if defined) in a list and call
2647 ;; make-comint.
2648 (let ((params))
2649 (if (not (string= "" sql-database))
2650 (setq params (append (list sql-database) params)))
2651 (if (not (string= "" sql-server))
2652 (setq params (append (list (concat "--host=" sql-server)) params)))
2653 (if (not (string= "" sql-password))
2654 (setq params (append (list (concat "--password=" sql-password)) params)))
2655 (if (not (string= "" sql-user))
2656 (setq params (append (list (concat "--user=" sql-user)) params)))
2657 (if (not (null sql-mysql-options))
2658 (setq params (append sql-mysql-options params)))
2659 (set-buffer (apply 'make-comint "SQL" sql-mysql-program
2660 nil params))))
95e4b2ef
RS
2661
2662\f
2663
77d352a6 2664;;;###autoload
dab100d7
RS
2665(defun sql-solid ()
2666 "Run solsql by Solid as an inferior process.
2667
2668If buffer `*SQL*' exists but no process is running, make a new process.
2669If buffer exists and a process is running, just switch to buffer
2670`*SQL*'.
2671
2672Interpreter used comes from variable `sql-solid-program'. Login uses
2673the variables `sql-user', `sql-password', and `sql-server' as
2674defaults, if set.
2675
2676The buffer is put in sql-interactive-mode, giving commands for sending
2677input. See `sql-interactive-mode'.
2678
2679To specify a coding system for converting non-ASCII characters
2680in the input and output to the process, use \\[universal-coding-system-argument]
2681before \\[sql-solid]. You can also specify this with \\[set-buffer-process-coding-system]
2682in the SQL buffer, after you start the process.
2683The default comes from `process-coding-system-alist' and
2684`default-process-coding-system'.
2685
2686\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2687 (interactive)
78024f88
AS
2688 (sql-product-interactive 'solid))
2689
2690(defun sql-connect-solid ()
2691 "Create comint buffer and connect to Solid using the login
2692parameters and command options."
2693 ;; Put all parameters to the program (if defined) in a list and call
2694 ;; make-comint.
2695 (let ((params))
2696 ;; It only makes sense if both username and password are there.
2697 (if (not (or (string= "" sql-user)
2698 (string= "" sql-password)))
2699 (setq params (append (list sql-user sql-password) params)))
2700 (if (not (string= "" sql-server))
2701 (setq params (append (list sql-server) params)))
2702 (set-buffer (apply 'make-comint "SQL" sql-solid-program
2703 nil params))))
dab100d7
RS
2704
2705\f
2706
77d352a6 2707;;;###autoload
95e4b2ef
RS
2708(defun sql-ingres ()
2709 "Run sql by Ingres as an inferior process.
2710
dab100d7 2711If buffer `*SQL*' exists but no process is running, make a new process.
95e4b2ef
RS
2712If buffer exists and a process is running, just switch to buffer
2713`*SQL*'.
2714
2715Interpreter used comes from variable `sql-ingres-program'. Login uses
2716the variable `sql-database' as default, if set.
2717
2718The buffer is put in sql-interactive-mode, giving commands for sending
2719input. See `sql-interactive-mode'.
2720
2721To specify a coding system for converting non-ASCII characters
2722in the input and output to the process, use \\[universal-coding-system-argument]
2723before \\[sql-ingres]. You can also specify this with \\[set-buffer-process-coding-system]
2724in the SQL buffer, after you start the process.
2725The default comes from `process-coding-system-alist' and
2726`default-process-coding-system'.
2727
2728\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2729 (interactive)
78024f88
AS
2730 (sql-product-interactive 'ingres))
2731
2732(defun sql-connect-ingres ()
2733 "Create comint buffer and connect to Ingres using the login
2734parameters and command options."
2735 ;; username and password are ignored.
2736 (if (string= "" sql-database)
2737 (set-buffer (make-comint "SQL" sql-ingres-program nil))
2738 (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database))))
95e4b2ef
RS
2739
2740\f
2741
77d352a6 2742;;;###autoload
95e4b2ef 2743(defun sql-ms ()
78024f88 2744 "Run osql by Microsoft as an inferior process.
95e4b2ef 2745
dab100d7 2746If buffer `*SQL*' exists but no process is running, make a new process.
95e4b2ef
RS
2747If buffer exists and a process is running, just switch to buffer
2748`*SQL*'.
2749
2750Interpreter used comes from variable `sql-ms-program'. Login uses the
dab100d7 2751variables `sql-user', `sql-password', `sql-database', and `sql-server'
f4df536d
JB
2752as defaults, if set. Additional command line parameters can be stored
2753in the list `sql-ms-options'.
95e4b2ef
RS
2754
2755The buffer is put in sql-interactive-mode, giving commands for sending
2756input. See `sql-interactive-mode'.
2757
2758To specify a coding system for converting non-ASCII characters
2759in the input and output to the process, use \\[universal-coding-system-argument]
dab100d7 2760before \\[sql-ms]. You can also specify this with \\[set-buffer-process-coding-system]
95e4b2ef
RS
2761in the SQL buffer, after you start the process.
2762The default comes from `process-coding-system-alist' and
2763`default-process-coding-system'.
2764
2765\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2766 (interactive)
78024f88
AS
2767 (sql-product-interactive 'ms))
2768
2769(defun sql-connect-ms ()
2770 "Create comint buffer and connect to Microsoft using the login
2771parameters and command options."
2772 ;; Put all parameters to the program (if defined) in a list and call
2773 ;; make-comint.
2774 (let ((params sql-ms-options))
2775 (if (not (string= "" sql-server))
95e4b2ef 2776 (setq params (append (list "-S" sql-server) params)))
78024f88 2777 (if (not (string= "" sql-database))
95e4b2ef 2778 (setq params (append (list "-d" sql-database) params)))
78024f88
AS
2779 (if (not (string= "" sql-user))
2780 (setq params (append (list "-U" sql-user) params)))
2781 (if (not (string= "" sql-password))
2782 (setq params (append (list "-P" sql-password) params))
2783 (if (string= "" sql-user)
2784 ;; if neither user nor password is provided, use system
2785 ;; credentials.
2786 (setq params (append (list "-E") params))
2787 ;; If -P is passed to ISQL as the last argument without a
2788 ;; password, it's considered null.
2789 (setq params (append params (list "-P")))))
2790 (set-buffer (apply 'make-comint "SQL" sql-ms-program
2791 nil params))))
95e4b2ef 2792
95e4b2ef
RS
2793\f
2794
2795;;;###autoload
2796(defun sql-postgres ()
2797 "Run psql by Postgres as an inferior process.
2798
dab100d7 2799If buffer `*SQL*' exists but no process is running, make a new process.
95e4b2ef
RS
2800If buffer exists and a process is running, just switch to buffer
2801`*SQL*'.
2802
2803Interpreter used comes from variable `sql-postgres-program'. Login uses
c04bb32e 2804the variables `sql-database' and `sql-server' as default, if set.
7a65c85c
GM
2805Additional command line parameters can be stored in the list
2806`sql-postgres-options'.
95e4b2ef
RS
2807
2808The buffer is put in sql-interactive-mode, giving commands for sending
2809input. See `sql-interactive-mode'.
2810
2811To specify a coding system for converting non-ASCII characters
2812in the input and output to the process, use \\[universal-coding-system-argument]
2813before \\[sql-postgres]. You can also specify this with \\[set-buffer-process-coding-system]
2814in the SQL buffer, after you start the process.
2815The default comes from `process-coding-system-alist' and
801d1cb0 2816`default-process-coding-system'. If your output lines end with ^M,
95e4b2ef
RS
2817your might try undecided-dos as a coding system. If this doesn't help,
2818Try to set `comint-output-filter-functions' like this:
2819
2820\(setq comint-output-filter-functions (append comint-output-filter-functions
2821 '(comint-strip-ctrl-m)))
2822
2823\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2824 (interactive)
78024f88
AS
2825 (sql-product-interactive 'postgres))
2826
2827(defun sql-connect-postgres ()
2828 "Create comint buffer and connect to Postgres using the login
2829parameters and command options."
2830 ;; username and password are ignored. Mark Stosberg suggest to add
2831 ;; the database at the end. Jason Beegan suggest using --pset and
2832 ;; pager=off instead of \\o|cat. The later was the solution by
2833 ;; Gregor Zych. Jason's suggestion is the default value for
2834 ;; sql-postgres-options.
2835 (let ((params sql-postgres-options))
2836 (if (not (string= "" sql-database))
2837 (setq params (append params (list sql-database))))
2838 (if (not (string= "" sql-server))
2839 (setq params (append (list "-h" sql-server) params)))
9fd8cb36
SM
2840 (if (not (string= "" sql-user))
2841 (setq params (append (list "-U" sql-user) params)))
78024f88
AS
2842 (set-buffer (apply 'make-comint "SQL" sql-postgres-program
2843 nil params))))
95e4b2ef 2844
eb3f61dd
GM
2845\f
2846
2847;;;###autoload
2848(defun sql-interbase ()
2849 "Run isql by Interbase as an inferior process.
2850
2851If buffer `*SQL*' exists but no process is running, make a new process.
2852If buffer exists and a process is running, just switch to buffer
2853`*SQL*'.
2854
2855Interpreter used comes from variable `sql-interbase-program'. Login
2856uses the variables `sql-user', `sql-password', and `sql-database' as
2857defaults, if set.
2858
2859The buffer is put in sql-interactive-mode, giving commands for sending
2860input. See `sql-interactive-mode'.
2861
2862To specify a coding system for converting non-ASCII characters
2863in the input and output to the process, use \\[universal-coding-system-argument]
2864before \\[sql-interbase]. You can also specify this with \\[set-buffer-process-coding-system]
2865in the SQL buffer, after you start the process.
2866The default comes from `process-coding-system-alist' and
2867`default-process-coding-system'.
2868
2869\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2870 (interactive)
78024f88
AS
2871 (sql-product-interactive 'interbase))
2872
2873(defun sql-connect-interbase ()
2874 "Create comint buffer and connect to Interbase using the login
2875parameters and command options."
2876 ;; Put all parameters to the program (if defined) in a list and call
2877 ;; make-comint.
2878 (let ((params sql-interbase-options))
2879 (if (not (string= "" sql-user))
2880 (setq params (append (list "-u" sql-user) params)))
2881 (if (not (string= "" sql-password))
2882 (setq params (append (list "-p" sql-password) params)))
2883 (if (not (string= "" sql-database))
2884 (setq params (cons sql-database params))) ; add to the front!
2885 (set-buffer (apply 'make-comint "SQL" sql-interbase-program
2886 nil params))))
eb3f61dd 2887
624ef9b3
GM
2888\f
2889
2890;;;###autoload
2891(defun sql-db2 ()
2892 "Run db2 by IBM as an inferior process.
2893
2894If buffer `*SQL*' exists but no process is running, make a new process.
2895If buffer exists and a process is running, just switch to buffer
2896`*SQL*'.
2897
2898Interpreter used comes from variable `sql-db2-program'. There is not
2899automatic login.
2900
2901The buffer is put in sql-interactive-mode, giving commands for sending
2902input. See `sql-interactive-mode'.
2903
aa88e662
GM
2904If you use \\[sql-accumulate-and-indent] to send multiline commands to
2905db2, newlines will be escaped if necessary. If you don't want that, set
2906`comint-input-sender' back to `comint-simple-send' by writing an after
2907advice. See the elisp manual for more information.
624ef9b3
GM
2908
2909To specify a coding system for converting non-ASCII characters
2910in the input and output to the process, use \\[universal-coding-system-argument]
2911before \\[sql-db2]. You can also specify this with \\[set-buffer-process-coding-system]
2912in the SQL buffer, after you start the process.
2913The default comes from `process-coding-system-alist' and
2914`default-process-coding-system'.
2915
2916\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2917 (interactive)
78024f88
AS
2918 (sql-product-interactive 'db2))
2919
2920(defun sql-connect-db2 ()
2921 "Create comint buffer and connect to DB2 using the login
2922parameters and command options."
2923 ;; Put all parameters to the program (if defined) in a list and call
2924 ;; make-comint.
2925 (set-buffer (apply 'make-comint "SQL" sql-db2-program
2926 nil sql-db2-options))
2927 ;; Properly escape newlines when DB2 is interactive.
2928 (setq comint-input-sender 'sql-escape-newlines-and-send))
624ef9b3 2929
f4df536d
JB
2930;;;###autoload
2931(defun sql-linter ()
2932 "Run inl by RELEX as an inferior process.
2933
2934If buffer `*SQL*' exists but no process is running, make a new process.
2935If buffer exists and a process is running, just switch to buffer
2936`*SQL*'.
2937
2938Interpreter used comes from variable `sql-linter-program' - usually `inl'.
2939Login uses the variables `sql-user', `sql-password', `sql-database' and
2940`sql-server' as defaults, if set. Additional command line parameters
2941can be stored in the list `sql-linter-options'. Run inl -h to get help on
2942parameters.
2943
2944`sql-database' is used to set the LINTER_MBX environment variable for
2945local connections, `sql-server' refers to the server name from the
2946`nodetab' file for the network connection (dbc_tcp or friends must run
2947for this to work). If `sql-password' is an empty string, inl will use
2948an empty password.
2949
2950The buffer is put in sql-interactive-mode, giving commands for sending
2951input. See `sql-interactive-mode'.
2952
f4df536d
JB
2953\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2954 (interactive)
78024f88
AS
2955 (sql-product-interactive 'linter))
2956
2957(defun sql-connect-linter ()
2958 "Create comint buffer and connect to Linter using the login
2959parameters and command options."
2960 ;; Put all parameters to the program (if defined) in a list and call
2961 ;; make-comint.
2962 (let ((params sql-linter-options) (login nil) (old-mbx (getenv "LINTER_MBX")))
2963 (if (not (string= "" sql-user))
2964 (setq login (concat sql-user "/" sql-password)))
2965 (setq params (append (list "-u" login) params))
2966 (if (not (string= "" sql-server))
2967 (setq params (append (list "-n" sql-server) params)))
2968 (if (string= "" sql-database)
2969 (setenv "LINTER_MBX" nil)
2970 (setenv "LINTER_MBX" sql-database))
2971 (set-buffer (apply 'make-comint "SQL" sql-linter-program nil
2972 params))
2973 (setenv "LINTER_MBX" old-mbx)))
f4df536d
JB
2974
2975\f
2976
95e4b2ef
RS
2977(provide 'sql)
2978
ab5796a9 2979;;; arch-tag: 7e1fa1c4-9ca2-402e-87d2-83a5eccb7ac3
95e4b2ef 2980;;; sql.el ends here