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