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