]> code.delx.au - gnu-emacs/blob - lisp/progmodes/sql.el
SQL Mode 2.7: Code cleanup and primatives for SQL redirection
[gnu-emacs] / lisp / progmodes / sql.el
1 ;;; sql.el --- specialized comint.el for SQL interpreters
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5
6 ;; Author: Alex Schroeder <alex@gnu.org>
7 ;; Maintainer: Michael Mauger <mmaug@yahoo.com>
8 ;; Version: 2.7
9 ;; Keywords: comm languages processes
10 ;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el
11 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode
12
13 ;; This file is part of GNU Emacs.
14
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
19
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
24
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27
28 ;;; Commentary:
29
30 ;; Please send bug reports and bug fixes to the mailing list at
31 ;; help-gnu-emacs@gnu.org. If you want to subscribe to the mailing
32 ;; list, see the web page at
33 ;; http://lists.gnu.org/mailman/listinfo/help-gnu-emacs for
34 ;; instructions. I monitor this list actively. If you send an e-mail
35 ;; to Alex Schroeder it usually makes it to me when Alex has a chance
36 ;; to forward them along (Thanks, Alex).
37
38 ;; This file provides a sql-mode and a sql-interactive-mode. The
39 ;; original goals were two simple modes providing syntactic
40 ;; highlighting. The interactive mode had to provide a command-line
41 ;; history; the other mode had to provide "send region/buffer to SQL
42 ;; interpreter" functions. "simple" in this context means easy to
43 ;; use, easy to maintain and little or no bells and whistles. This
44 ;; has changed somewhat as experience with the mode has accumulated.
45
46 ;; Support for different flavors of SQL and command interpreters was
47 ;; available in early versions of sql.el. This support has been
48 ;; extended and formalized in later versions. Part of the impetus for
49 ;; the improved support of SQL flavors was borne out of the current
50 ;; maintainer's consulting experience. In the past fifteen years, I
51 ;; have used Oracle, Sybase, Informix, MySQL, Postgres, and SQLServer.
52 ;; On some assignments, I have used two or more of these concurrently.
53
54 ;; If anybody feels like extending this sql mode, take a look at the
55 ;; above mentioned modes and write a sqlx-mode on top of this one. If
56 ;; this proves to be difficult, please suggest changes that will
57 ;; facilitate your plans. Facilities have been provided to add
58 ;; products and product-specific configuration.
59
60 ;; sql-interactive-mode is used to interact with a SQL interpreter
61 ;; process in a SQLi buffer (usually called `*SQL*'). The SQLi buffer
62 ;; is created by calling a SQL interpreter-specific entry function or
63 ;; sql-product-interactive. Do *not* call sql-interactive-mode by
64 ;; itself.
65
66 ;; The list of currently supported interpreters and the corresponding
67 ;; entry function used to create the SQLi buffers is shown with
68 ;; `sql-help' (M-x sql-help).
69
70 ;; Since sql-interactive-mode is built on top of the general
71 ;; command-interpreter-in-a-buffer mode (comint mode), it shares a
72 ;; common base functionality, and a common set of bindings, with all
73 ;; modes derived from comint mode. This makes these modes easier to
74 ;; use.
75
76 ;; sql-mode can be used to keep editing SQL statements. The SQL
77 ;; statements can be sent to the SQL process in the SQLi buffer.
78
79 ;; For documentation on the functionality provided by comint mode, and
80 ;; the hooks available for customizing it, see the file `comint.el'.
81
82 ;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and
83 ;; `imenu-add-menubar-index'.
84
85 ;;; Requirements for Emacs 19.34:
86
87 ;; If you are using Emacs 19.34, you will have to get and install
88 ;; the file regexp-opt.el
89 ;; <URL:ftp://ftp.ifi.uio.no/pub/emacs/emacs-20.3/lisp/emacs-lisp/regexp-opt.el>
90 ;; and the custom package
91 ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>.
92
93 ;;; Bugs:
94
95 ;; sql-ms now uses osql instead of isql. Osql flushes its error
96 ;; stream more frequently than isql so that error messages are
97 ;; available. There is no prompt and some output still is buffered.
98 ;; This improves the interaction under Emacs but it still is somewhat
99 ;; awkward.
100
101 ;; Quoted identifiers are not supported for hilighting. Most
102 ;; databases support the use of double quoted strings in place of
103 ;; identifiers; ms (Microsoft SQLServer) also supports identifiers
104 ;; enclosed within brackets [].
105
106 ;;; Product Support:
107
108 ;; To add support for additional SQL products the following steps
109 ;; must be followed ("xyz" is the name of the product in the examples
110 ;; below):
111
112 ;; 1) Add the product to the list of known products.
113
114 ;; (sql-add-product 'xyz "XyzDB"
115 ;; '(:free-software t))
116
117 ;; 2) Define font lock settings. All ANSI keywords will be
118 ;; highlighted automatically, so only product specific keywords
119 ;; need to be defined here.
120
121 ;; (defvar my-sql-mode-xyz-font-lock-keywords
122 ;; '(("\\b\\(red\\|orange\\|yellow\\)\\b"
123 ;; . font-lock-keyword-face))
124 ;; "XyzDB SQL keywords used by font-lock.")
125
126 ;; (sql-set-product-feature 'xyz
127 ;; :font-lock
128 ;; 'my-sql-mode-xyz-font-lock-keywords)
129
130 ;; 3) Define any special syntax characters including comments and
131 ;; identifier characters.
132
133 ;; (sql-set-product-feature 'xyz
134 ;; :syntax-alist ((?# . "w")))
135
136 ;; 4) Define the interactive command interpreter for the database
137 ;; product.
138
139 ;; (defcustom my-sql-xyz-program "ixyz"
140 ;; "Command to start ixyz by XyzDB."
141 ;; :type 'file
142 ;; :group 'SQL)
143 ;;
144 ;; (sql-set-product-feature 'xyz
145 ;; :sqli-program 'my-sql-xyz-program)
146 ;; (sql-set-product-feature 'xyz
147 ;; :prompt-regexp "^xyzdb> ")
148 ;; (sql-set-product-feature 'xyz
149 ;; :prompt-length 7)
150
151 ;; 5) Define login parameters and command line formatting.
152
153 ;; (defcustom my-sql-xyz-login-params '(user password server database)
154 ;; "Login parameters to needed to connect to XyzDB."
155 ;; :type 'sql-login-params
156 ;; :group 'SQL)
157 ;;
158 ;; (sql-set-product-feature 'xyz
159 ;; :sqli-login 'my-sql-xyz-login-params)
160
161 ;; (defcustom my-sql-xyz-options '("-X" "-Y" "-Z")
162 ;; "List of additional options for `sql-xyz-program'."
163 ;; :type '(repeat string)
164 ;; :group 'SQL)
165 ;;
166 ;; (sql-set-product-feature 'xyz
167 ;; :sqli-options 'my-sql-xyz-options))
168
169 ;; (defun my-sql-comint-xyz (product options)
170 ;; "Connect ti XyzDB in a comint buffer."
171 ;;
172 ;; ;; Do something with `sql-user', `sql-password',
173 ;; ;; `sql-database', and `sql-server'.
174 ;; (let ((params options))
175 ;; (if (not (string= "" sql-server))
176 ;; (setq params (append (list "-S" sql-server) params)))
177 ;; (if (not (string= "" sql-database))
178 ;; (setq params (append (list "-D" sql-database) params)))
179 ;; (if (not (string= "" sql-password))
180 ;; (setq params (append (list "-P" sql-password) params)))
181 ;; (if (not (string= "" sql-user))
182 ;; (setq params (append (list "-U" sql-user) params)))
183 ;; (sql-comint product params)))
184 ;;
185 ;; (sql-set-product-feature 'xyz
186 ;; :sqli-comint-func 'my-sql-comint-xyz)
187
188 ;; 6) Define a convienence function to invoke the SQL interpreter.
189
190 ;; (defun my-sql-xyz (&optional buffer)
191 ;; "Run ixyz by XyzDB as an inferior process."
192 ;; (interactive "P")
193 ;; (sql-product-interactive 'xyz buffer))
194
195 ;;; To Do:
196
197 ;; Improve keyword highlighting for individual products. I have tried
198 ;; to update those database that I use. Feel free to send me updates,
199 ;; or direct me to the reference manuals for your favorite database.
200
201 ;; When there are no keywords defined, the ANSI keywords are
202 ;; highlighted. ANSI keywords are highlighted even if the keyword is
203 ;; not used for your current product. This should help identify
204 ;; portability concerns.
205
206 ;; Add different highlighting levels.
207
208 ;; Add support for listing available tables or the columns in a table.
209
210 ;;; Thanks to all the people who helped me out:
211
212 ;; Alex Schroeder <alex@gnu.org> -- the original author
213 ;; Kai Blauberg <kai.blauberg@metla.fi>
214 ;; <ibalaban@dalet.com>
215 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il>
216 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
217 ;; nino <nino@inform.dk>
218 ;; Berend de Boer <berend@pobox.com>
219 ;; Adam Jenkins <adam@thejenkins.org>
220 ;; Michael Mauger <mmaug@yahoo.com> -- improved product support
221 ;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support
222 ;; Harald Maier <maierh@myself.com> -- sql-send-string
223 ;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections; code polish
224
225 \f
226
227 ;;; Code:
228
229 (require 'comint)
230 ;; Need the following to allow GNU Emacs 19 to compile the file.
231 (eval-when-compile
232 (require 'regexp-opt))
233 (require 'custom)
234 (eval-when-compile ;; needed in Emacs 19, 20
235 (setq max-specpdl-size (max max-specpdl-size 2000)))
236
237 (defvar font-lock-keyword-face)
238 (defvar font-lock-set-defaults)
239 (defvar font-lock-string-face)
240
241 ;;; Allow customization
242
243 (defgroup SQL nil
244 "Running a SQL interpreter from within Emacs buffers."
245 :version "20.4"
246 :group 'languages
247 :group 'processes)
248
249 ;; These four variables will be used as defaults, if set.
250
251 (defcustom sql-user ""
252 "Default username."
253 :type 'string
254 :group 'SQL
255 :safe 'stringp)
256
257 (defcustom sql-password ""
258 "Default password.
259
260 Storing your password in a textfile such as ~/.emacs could be dangerous.
261 Customizing your password will store it in your ~/.emacs file."
262 :type 'string
263 :group 'SQL
264 :risky t)
265
266 (defcustom sql-database ""
267 "Default database."
268 :type 'string
269 :group 'SQL
270 :safe 'stringp)
271
272 (defcustom sql-server ""
273 "Default server or host."
274 :type 'string
275 :group 'SQL
276 :safe 'stringp)
277
278 (defcustom sql-port 0
279 "Default port."
280 :version "24.1"
281 :type 'number
282 :group 'SQL
283 :safe 'numberp)
284
285 ;; Login parameter type
286
287 (define-widget 'sql-login-params 'lazy
288 "Widget definition of the login parameters list"
289 :tag "Login Parameters"
290 :type '(repeat (choice
291 (const user)
292 (const password)
293 (choice :tag "server"
294 (const server)
295 (list :tag "file"
296 (const :format "" server)
297 (const :format "" :file)
298 regexp)
299 (list :tag "completion"
300 (const :format "" server)
301 (const :format "" :completion)
302 (restricted-sexp
303 :match-alternatives (listp symbolp))))
304 (choice :tag "database"
305 (const database)
306 (list :tag "file"
307 (const :format "" database)
308 (const :format "" :file)
309 regexp)
310 (list :tag "completion"
311 (const :format "" database)
312 (const :format "" :completion)
313 (restricted-sexp
314 :match-alternatives (listp symbolp))))
315 (const port))))
316
317 ;; SQL Product support
318
319 (defvar sql-interactive-product nil
320 "Product under `sql-interactive-mode'.")
321
322 (defvar sql-connection nil
323 "Connection name if interactive session started by `sql-connect'.")
324
325 (defvar sql-product-alist
326 '((ansi
327 :name "ANSI"
328 :font-lock sql-mode-ansi-font-lock-keywords)
329
330 (db2
331 :name "DB2"
332 :font-lock sql-mode-db2-font-lock-keywords
333 :sqli-program sql-db2-program
334 :sqli-options sql-db2-options
335 :sqli-login sql-db2-login-params
336 :sqli-comint-func sql-comint-db2
337 :prompt-regexp "^db2 => "
338 :prompt-length 7
339 :prompt-cont-regexp "^db2 (cont\.) => "
340 :input-filter sql-escape-newlines-filter)
341
342 (informix
343 :name "Informix"
344 :font-lock sql-mode-informix-font-lock-keywords
345 :sqli-program sql-informix-program
346 :sqli-options sql-informix-options
347 :sqli-login sql-informix-login-params
348 :sqli-comint-func sql-comint-informix
349 :prompt-regexp "^> "
350 :prompt-length 2
351 :syntax-alist ((?{ . "<") (?} . ">")))
352
353 (ingres
354 :name "Ingres"
355 :font-lock sql-mode-ingres-font-lock-keywords
356 :sqli-program sql-ingres-program
357 :sqli-options sql-ingres-options
358 :sqli-login sql-ingres-login-params
359 :sqli-comint-func sql-comint-ingres
360 :prompt-regexp "^\* "
361 :prompt-length 2
362 :prompt-cont-regexp "^\* ")
363
364 (interbase
365 :name "Interbase"
366 :font-lock sql-mode-interbase-font-lock-keywords
367 :sqli-program sql-interbase-program
368 :sqli-options sql-interbase-options
369 :sqli-login sql-interbase-login-params
370 :sqli-comint-func sql-comint-interbase
371 :prompt-regexp "^SQL> "
372 :prompt-length 5)
373
374 (linter
375 :name "Linter"
376 :font-lock sql-mode-linter-font-lock-keywords
377 :sqli-program sql-linter-program
378 :sqli-options sql-linter-options
379 :sqli-login sql-linter-login-params
380 :sqli-comint-func sql-comint-linter
381 :prompt-regexp "^SQL>"
382 :prompt-length 4)
383
384 (ms
385 :name "Microsoft"
386 :font-lock sql-mode-ms-font-lock-keywords
387 :sqli-program sql-ms-program
388 :sqli-options sql-ms-options
389 :sqli-login sql-ms-login-params
390 :sqli-comint-func sql-comint-ms
391 :prompt-regexp "^[0-9]*>"
392 :prompt-length 5
393 :syntax-alist ((?@ . "w"))
394 :terminator ("^go" . "go"))
395
396 (mysql
397 :name "MySQL"
398 :free-software t
399 :font-lock sql-mode-mysql-font-lock-keywords
400 :sqli-program sql-mysql-program
401 :sqli-options sql-mysql-options
402 :sqli-login sql-mysql-login-params
403 :sqli-comint-func sql-comint-mysql
404 :prompt-regexp "^mysql> "
405 :prompt-length 6
406 :prompt-cont-regexp "^ -> "
407 :input-filter sql-remove-tabs-filter)
408
409 (oracle
410 :name "Oracle"
411 :font-lock sql-mode-oracle-font-lock-keywords
412 :sqli-program sql-oracle-program
413 :sqli-options sql-oracle-options
414 :sqli-login sql-oracle-login-params
415 :sqli-comint-func sql-comint-oracle
416 :prompt-regexp "^SQL> "
417 :prompt-length 5
418 :prompt-cont-regexp "^\\s-*\\d+> "
419 :syntax-alist ((?$ . "w") (?# . "w"))
420 :terminator ("\\(^/\\|;\\)" . "/")
421 :input-filter sql-placeholders-filter)
422
423 (postgres
424 :name "Postgres"
425 :free-software t
426 :font-lock sql-mode-postgres-font-lock-keywords
427 :sqli-program sql-postgres-program
428 :sqli-options sql-postgres-options
429 :sqli-login sql-postgres-login-params
430 :sqli-comint-func sql-comint-postgres
431 :prompt-regexp "^.*=[#>] "
432 :prompt-length 5
433 :prompt-cont-regexp "^.*[-(][#>] "
434 :input-filter sql-remove-tabs-filter
435 :terminator ("\\(^\\s-*\\\\g\\|;\\)" . ";"))
436
437 (solid
438 :name "Solid"
439 :font-lock sql-mode-solid-font-lock-keywords
440 :sqli-program sql-solid-program
441 :sqli-options sql-solid-options
442 :sqli-login sql-solid-login-params
443 :sqli-comint-func sql-comint-solid
444 :prompt-regexp "^"
445 :prompt-length 0)
446
447 (sqlite
448 :name "SQLite"
449 :free-software t
450 :font-lock sql-mode-sqlite-font-lock-keywords
451 :sqli-program sql-sqlite-program
452 :sqli-options sql-sqlite-options
453 :sqli-login sql-sqlite-login-params
454 :sqli-comint-func sql-comint-sqlite
455 :prompt-regexp "^sqlite> "
456 :prompt-length 8
457 :prompt-cont-regexp "^ ...> "
458 :terminator ";")
459
460 (sybase
461 :name "Sybase"
462 :font-lock sql-mode-sybase-font-lock-keywords
463 :sqli-program sql-sybase-program
464 :sqli-options sql-sybase-options
465 :sqli-login sql-sybase-login-params
466 :sqli-comint-func sql-comint-sybase
467 :prompt-regexp "^SQL> "
468 :prompt-length 5
469 :syntax-alist ((?@ . "w"))
470 :terminator ("^go" . "go"))
471 )
472 "An alist of product specific configuration settings.
473
474 Without an entry in this list a product will not be properly
475 highlighted and will not support `sql-interactive-mode'.
476
477 Each element in the list is in the following format:
478
479 \(PRODUCT FEATURE VALUE ...)
480
481 where PRODUCT is the appropriate value of `sql-product'. The
482 product name is then followed by FEATURE-VALUE pairs. If a
483 FEATURE is not specified, its VALUE is treated as nil. FEATURE
484 may be any one of the following:
485
486 :name string containing the displayable name of
487 the product.
488
489 :free-software is the product Free (as in Freedom) software?
490
491 :font-lock name of the variable containing the product
492 specific font lock highlighting patterns.
493
494 :sqli-program name of the variable containing the product
495 specific interactive program name.
496
497 :sqli-options name of the variable containing the list
498 of product specific options.
499
500 :sqli-login name of the variable containing the list of
501 login parameters (i.e., user, password,
502 database and server) needed to connect to
503 the database.
504
505 :sqli-comint-func name of a function which accepts no
506 parameters that will use the values of
507 `sql-user', `sql-password',
508 `sql-database' and `sql-server' to open a
509 comint buffer and connect to the
510 database. Do product specific
511 configuration of comint in this function.
512
513 :prompt-regexp regular expression string that matches
514 the prompt issued by the product
515 interpreter.
516
517 :prompt-length length of the prompt on the line.
518
519 :prompt-cont-regexp regular expression string that matches
520 the continuation prompt issued by the
521 product interpreter.
522
523 :input-filter function which can filter strings sent to
524 the command interpreter. It is also used
525 by the `sql-send-string',
526 `sql-send-region', `sql-send-paragraph'
527 and `sql-send-buffer' functions. The
528 function is passed the string sent to the
529 command interpreter and must return the
530 filtered string. May also be a list of
531 such functions.
532
533 :terminator the terminator to be sent after a
534 `sql-send-string', `sql-send-region',
535 `sql-send-paragraph' and
536 `sql-send-buffer' command. May be the
537 literal string or a cons of a regexp to
538 match an existing terminator in the
539 string and the terminator to be used if
540 its absent. By default \";\".
541
542 :syntax-alist alist of syntax table entries to enable
543 special character treatment by font-lock
544 and imenu.
545
546 Other features can be stored but they will be ignored. However,
547 you can develop new functionality which is product independent by
548 using `sql-get-product-feature' to lookup the product specific
549 settings.")
550
551 (defvar sql-indirect-features
552 '(:font-lock :sqli-program :sqli-options :sqli-login))
553
554 (defcustom sql-connection-alist nil
555 "An alist of connection parameters for interacting with a SQL
556 product.
557
558 Each element of the alist is as follows:
559
560 \(CONNECTION \(SQL-VARIABLE VALUE) ...)
561
562 Where CONNECTION is a symbol identifying the connection, SQL-VARIABLE
563 is the symbol name of a SQL mode variable, and VALUE is the value to
564 be assigned to the variable.
565
566 The most common SQL-VARIABLE settings associated with a connection
567 are:
568
569 `sql-product'
570 `sql-user'
571 `sql-password'
572 `sql-port'
573 `sql-server'
574 `sql-database'
575
576 If a SQL-VARIABLE is part of the connection, it will not be
577 prompted for during login."
578
579 :type `(alist :key-type (string :tag "Connection")
580 :value-type
581 (set
582 (group (const :tag "Product" sql-product)
583 (choice
584 ,@(mapcar (lambda (prod-info)
585 `(const :tag
586 ,(or (plist-get (cdr prod-info) :name)
587 (capitalize (symbol-name (car prod-info))))
588 (quote ,(car prod-info))))
589 sql-product-alist)))
590 (group (const :tag "Username" sql-user) string)
591 (group (const :tag "Password" sql-password) string)
592 (group (const :tag "Server" sql-server) string)
593 (group (const :tag "Database" sql-database) string)
594 (group (const :tag "Port" sql-port) integer)
595 (repeat :inline t
596 (list :tab "Other"
597 (symbol :tag " Variable Symbol")
598 (sexp :tag "Value Expression")))))
599 :version "24.1"
600 :group 'SQL)
601
602 (defcustom sql-product 'ansi
603 "Select the SQL database product used so that buffers can be
604 highlighted properly when you open them."
605 :type `(choice
606 ,@(mapcar (lambda (prod-info)
607 `(const :tag
608 ,(or (plist-get (cdr prod-info) :name)
609 (capitalize (symbol-name (car prod-info))))
610 ,(car prod-info)))
611 sql-product-alist))
612 :group 'SQL
613 :safe 'symbolp)
614 (defvaralias 'sql-dialect 'sql-product)
615
616 ;; misc customization of sql.el behaviour
617
618 (defcustom sql-electric-stuff nil
619 "Treat some input as electric.
620 If set to the symbol `semicolon', then hitting `;' will send current
621 input in the SQLi buffer to the process.
622 If set to the symbol `go', then hitting `go' on a line by itself will
623 send current input in the SQLi buffer to the process.
624 If set to nil, then you must use \\[comint-send-input] in order to send
625 current input in the SQLi buffer to the process."
626 :type '(choice (const :tag "Nothing" nil)
627 (const :tag "The semicolon `;'" semicolon)
628 (const :tag "The string `go' by itself" go))
629 :version "20.8"
630 :group 'SQL)
631
632 (defcustom sql-send-terminator nil
633 "When non-nil, add a terminator to text sent to the SQL interpreter.
634
635 When text is sent to the SQL interpreter (via `sql-send-string',
636 `sql-send-region', `sql-send-paragraph' or `sql-send-buffer'), a
637 command terminator can be automatically sent as well. The
638 terminator is not sent, if the string sent already ends with the
639 terminator.
640
641 If this value is t, then the default command terminator for the
642 SQL interpreter is sent. If this value is a string, then the
643 string is sent.
644
645 If the value is a cons cell of the form (PAT . TERM), then PAT is
646 a regexp used to match the terminator in the string and TERM is
647 the terminator to be sent. This form is useful if the SQL
648 interpreter has more than one way of submitting a SQL command.
649 The PAT regexp can match any of them, and TERM is the way we do
650 it automatically."
651
652 :type '(choice (const :tag "No Terminator" nil)
653 (const :tag "Default Terminator" t)
654 (string :tag "Terminator String")
655 (cons :tag "Terminator Pattern and String"
656 (string :tag "Terminator Pattern")
657 (string :tag "Terminator String")))
658 :version "22.2"
659 :group 'SQL)
660
661 (defcustom sql-pop-to-buffer-after-send-region nil
662 "When non-nil, pop to the buffer SQL statements are sent to.
663
664 After a call to `sql-sent-string', `sql-send-region',
665 `sql-send-paragraph' or `sql-send-buffer', the window is split
666 and the SQLi buffer is shown. If this variable is not nil, that
667 buffer's window will be selected by calling `pop-to-buffer'. If
668 this variable is nil, that buffer is shown using
669 `display-buffer'."
670 :type 'boolean
671 :group 'SQL)
672
673 ;; imenu support for sql-mode.
674
675 (defvar sql-imenu-generic-expression
676 ;; Items are in reverse order because they are rendered in reverse.
677 '(("Rules/Defaults" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(rule\\|default\\)\\s-+\\(\\w+\\)" 3)
678 ("Sequences" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*sequence\\s-+\\(\\w+\\)" 2)
679 ("Triggers" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*trigger\\s-+\\(\\w+\\)" 2)
680 ("Functions" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?function\\s-+\\(\\w+\\)" 3)
681 ("Procedures" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4)
682 ("Packages" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3)
683 ("Types" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*type\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3)
684 ("Indexes" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*index\\s-+\\(\\w+\\)" 2)
685 ("Tables/Views" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(table\\|view\\)\\s-+\\(\\w+\\)" 3))
686 "Define interesting points in the SQL buffer for `imenu'.
687
688 This is used to set `imenu-generic-expression' when SQL mode is
689 entered. Subsequent changes to `sql-imenu-generic-expression' will
690 not affect existing SQL buffers because imenu-generic-expression is
691 a local variable.")
692
693 ;; history file
694
695 (defcustom sql-input-ring-file-name nil
696 "If non-nil, name of the file to read/write input history.
697
698 You have to set this variable if you want the history of your commands
699 saved from one Emacs session to the next. If this variable is set,
700 exiting the SQL interpreter in an SQLi buffer will write the input
701 history to the specified file. Starting a new process in a SQLi buffer
702 will read the input history from the specified file.
703
704 This is used to initialize `comint-input-ring-file-name'.
705
706 Note that the size of the input history is determined by the variable
707 `comint-input-ring-size'."
708 :type '(choice (const :tag "none" nil)
709 (file))
710 :group 'SQL)
711
712 (defcustom sql-input-ring-separator "\n--\n"
713 "Separator between commands in the history file.
714
715 If set to \"\\n\", each line in the history file will be interpreted as
716 one command. Multi-line commands are split into several commands when
717 the input ring is initialized from a history file.
718
719 This variable used to initialize `comint-input-ring-separator'.
720 `comint-input-ring-separator' is part of Emacs 21; if your Emacs
721 does not have it, setting `sql-input-ring-separator' will have no
722 effect. In that case multiline commands will be split into several
723 commands when the input history is read, as if you had set
724 `sql-input-ring-separator' to \"\\n\"."
725 :type 'string
726 :group 'SQL)
727
728 ;; The usual hooks
729
730 (defcustom sql-interactive-mode-hook '()
731 "Hook for customizing `sql-interactive-mode'."
732 :type 'hook
733 :group 'SQL)
734
735 (defcustom sql-mode-hook '()
736 "Hook for customizing `sql-mode'."
737 :type 'hook
738 :group 'SQL)
739
740 (defcustom sql-set-sqli-hook '()
741 "Hook for reacting to changes of `sql-buffer'.
742
743 This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
744 is changed."
745 :type 'hook
746 :group 'SQL)
747
748 ;; Customization for Oracle
749
750 (defcustom sql-oracle-program "sqlplus"
751 "Command to start sqlplus by Oracle.
752
753 Starts `sql-interactive-mode' after doing some setup.
754
755 On Windows, \"sqlplus\" usually starts the sqlplus \"GUI\". In order
756 to start the sqlplus console, use \"plus33\" or something similar.
757 You will find the file in your Orant\\bin directory."
758 :type 'file
759 :group 'SQL)
760
761 (defcustom sql-oracle-options nil
762 "List of additional options for `sql-oracle-program'."
763 :type '(repeat string)
764 :version "20.8"
765 :group 'SQL)
766
767 (defcustom sql-oracle-login-params '(user password database)
768 "List of login parameters needed to connect to Oracle."
769 :type 'sql-login-params
770 :version "24.1"
771 :group 'SQL)
772
773 (defcustom sql-oracle-scan-on t
774 "Non-nil if placeholders should be replaced in Oracle SQLi.
775
776 When non-nil, Emacs will scan text sent to sqlplus and prompt
777 for replacement text for & placeholders as sqlplus does. This
778 is needed on Windows where sqlplus output is buffered and the
779 prompts are not shown until after the text is entered.
780
781 You will probably want to issue the following command in sqlplus
782 to be safe:
783
784 SET SCAN OFF"
785 :type 'boolean
786 :group 'SQL)
787
788 ;; Customization for SQLite
789
790 (defcustom sql-sqlite-program (or (executable-find "sqlite3")
791 (executable-find "sqlite")
792 "sqlite")
793 "Command to start SQLite.
794
795 Starts `sql-interactive-mode' after doing some setup."
796 :type 'file
797 :group 'SQL)
798
799 (defcustom sql-sqlite-options nil
800 "List of additional options for `sql-sqlite-program'."
801 :type '(repeat string)
802 :version "20.8"
803 :group 'SQL)
804
805 (defcustom sql-sqlite-login-params '((database :file ".*\\.\\(db\\|sqlite[23]?\\)"))
806 "List of login parameters needed to connect to SQLite."
807 :type 'sql-login-params
808 :version "24.1"
809 :group 'SQL)
810
811 ;; Customization for MySql
812
813 (defcustom sql-mysql-program "mysql"
814 "Command to start mysql by TcX.
815
816 Starts `sql-interactive-mode' after doing some setup."
817 :type 'file
818 :group 'SQL)
819
820 (defcustom sql-mysql-options nil
821 "List of additional options for `sql-mysql-program'.
822 The following list of options is reported to make things work
823 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
824 :type '(repeat string)
825 :version "20.8"
826 :group 'SQL)
827
828 (defcustom sql-mysql-login-params '(user password database server)
829 "List of login parameters needed to connect to MySql."
830 :type 'sql-login-params
831 :version "24.1"
832 :group 'SQL)
833
834 ;; Customization for Solid
835
836 (defcustom sql-solid-program "solsql"
837 "Command to start SOLID SQL Editor.
838
839 Starts `sql-interactive-mode' after doing some setup."
840 :type 'file
841 :group 'SQL)
842
843 (defcustom sql-solid-login-params '(user password server)
844 "List of login parameters needed to connect to Solid."
845 :type 'sql-login-params
846 :version "24.1"
847 :group 'SQL)
848
849 ;; Customization for Sybase
850
851 (defcustom sql-sybase-program "isql"
852 "Command to start isql by Sybase.
853
854 Starts `sql-interactive-mode' after doing some setup."
855 :type 'file
856 :group 'SQL)
857
858 (defcustom sql-sybase-options nil
859 "List of additional options for `sql-sybase-program'.
860 Some versions of isql might require the -n option in order to work."
861 :type '(repeat string)
862 :version "20.8"
863 :group 'SQL)
864
865 (defcustom sql-sybase-login-params '(server user password database)
866 "List of login parameters needed to connect to Sybase."
867 :type 'sql-login-params
868 :version "24.1"
869 :group 'SQL)
870
871 ;; Customization for Informix
872
873 (defcustom sql-informix-program "dbaccess"
874 "Command to start dbaccess by Informix.
875
876 Starts `sql-interactive-mode' after doing some setup."
877 :type 'file
878 :group 'SQL)
879
880 (defcustom sql-informix-login-params '(database)
881 "List of login parameters needed to connect to Informix."
882 :type 'sql-login-params
883 :version "24.1"
884 :group 'SQL)
885
886 ;; Customization for Ingres
887
888 (defcustom sql-ingres-program "sql"
889 "Command to start sql by Ingres.
890
891 Starts `sql-interactive-mode' after doing some setup."
892 :type 'file
893 :group 'SQL)
894
895 (defcustom sql-ingres-login-params '(database)
896 "List of login parameters needed to connect to Ingres."
897 :type 'sql-login-params
898 :version "24.1"
899 :group 'SQL)
900
901 ;; Customization for Microsoft
902
903 (defcustom sql-ms-program "osql"
904 "Command to start osql by Microsoft.
905
906 Starts `sql-interactive-mode' after doing some setup."
907 :type 'file
908 :group 'SQL)
909
910 (defcustom sql-ms-options '("-w" "300" "-n")
911 ;; -w is the linesize
912 "List of additional options for `sql-ms-program'."
913 :type '(repeat string)
914 :version "22.1"
915 :group 'SQL)
916
917 (defcustom sql-ms-login-params '(user password server database)
918 "List of login parameters needed to connect to Microsoft."
919 :type 'sql-login-params
920 :version "24.1"
921 :group 'SQL)
922
923 ;; Customization for Postgres
924
925 (defcustom sql-postgres-program "psql"
926 "Command to start psql by Postgres.
927
928 Starts `sql-interactive-mode' after doing some setup."
929 :type 'file
930 :group 'SQL)
931
932 (defcustom sql-postgres-options '("-P" "pager=off")
933 "List of additional options for `sql-postgres-program'.
934 The default setting includes the -P option which breaks older versions
935 of the psql client (such as version 6.5.3). The -P option is equivalent
936 to the --pset option. If you want the psql to prompt you for a user
937 name, add the string \"-u\" to the list of options. If you want to
938 provide a user name on the command line (newer versions such as 7.1),
939 add your name with a \"-U\" prefix (such as \"-Umark\") to the list."
940 :type '(repeat string)
941 :version "20.8"
942 :group 'SQL)
943
944 (defcustom sql-postgres-login-params '(user database server)
945 "List of login parameters needed to connect to Postgres."
946 :type 'sql-login-params
947 :version "24.1"
948 :group 'SQL)
949
950 ;; Customization for Interbase
951
952 (defcustom sql-interbase-program "isql"
953 "Command to start isql by Interbase.
954
955 Starts `sql-interactive-mode' after doing some setup."
956 :type 'file
957 :group 'SQL)
958
959 (defcustom sql-interbase-options nil
960 "List of additional options for `sql-interbase-program'."
961 :type '(repeat string)
962 :version "20.8"
963 :group 'SQL)
964
965 (defcustom sql-interbase-login-params '(user password database)
966 "List of login parameters needed to connect to Interbase."
967 :type 'sql-login-params
968 :version "24.1"
969 :group 'SQL)
970
971 ;; Customization for DB2
972
973 (defcustom sql-db2-program "db2"
974 "Command to start db2 by IBM.
975
976 Starts `sql-interactive-mode' after doing some setup."
977 :type 'file
978 :group 'SQL)
979
980 (defcustom sql-db2-options nil
981 "List of additional options for `sql-db2-program'."
982 :type '(repeat string)
983 :version "20.8"
984 :group 'SQL)
985
986 (defcustom sql-db2-login-params nil
987 "List of login parameters needed to connect to DB2."
988 :type 'sql-login-params
989 :version "24.1"
990 :group 'SQL)
991
992 ;; Customization for Linter
993
994 (defcustom sql-linter-program "inl"
995 "Command to start inl by RELEX.
996
997 Starts `sql-interactive-mode' after doing some setup."
998 :type 'file
999 :group 'SQL)
1000
1001 (defcustom sql-linter-options nil
1002 "List of additional options for `sql-linter-program'."
1003 :type '(repeat string)
1004 :version "21.3"
1005 :group 'SQL)
1006
1007 (defcustom sql-linter-login-params '(user password database server)
1008 "Login parameters to needed to connect to Linter."
1009 :type 'sql-login-params
1010 :version "24.1"
1011 :group 'SQL)
1012
1013 \f
1014
1015 ;;; Variables which do not need customization
1016
1017 (defvar sql-user-history nil
1018 "History of usernames used.")
1019
1020 (defvar sql-database-history nil
1021 "History of databases used.")
1022
1023 (defvar sql-server-history nil
1024 "History of servers used.")
1025
1026 ;; Passwords are not kept in a history.
1027
1028 (defvar sql-buffer nil
1029 "Current SQLi buffer.
1030
1031 The global value of `sql-buffer' is the name of the latest SQLi buffer
1032 created. Any SQL buffer created will make a local copy of this value.
1033 See `sql-interactive-mode' for more on multiple sessions. If you want
1034 to change the SQLi buffer a SQL mode sends its SQL strings to, change
1035 the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
1036
1037 (defvar sql-prompt-regexp nil
1038 "Prompt used to initialize `comint-prompt-regexp'.
1039
1040 You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.")
1041
1042 (defvar sql-prompt-length 0
1043 "Prompt used to set `left-margin' in `sql-interactive-mode'.
1044
1045 You can change `sql-prompt-length' on `sql-interactive-mode-hook'.")
1046
1047 (defvar sql-prompt-cont-regexp nil
1048 "Prompt pattern of statement continuation prompts.")
1049
1050 (defvar sql-alternate-buffer-name nil
1051 "Buffer-local string used to possibly rename the SQLi buffer.
1052
1053 Used by `sql-rename-buffer'.")
1054
1055 (defun sql-buffer-live-p (buffer &optional product)
1056 "Returns non-nil if the process associated with buffer is live.
1057
1058 BUFFER can be a buffer object or a buffer name. The buffer must
1059 be a live buffer, have an running process attached to it, be in
1060 `sql-interactive-mode', and, if PRODUCT is specified, it's
1061 `sql-product' must match."
1062
1063 (when buffer
1064 (setq buffer (get-buffer buffer))
1065 (and buffer
1066 (buffer-live-p buffer)
1067 (get-buffer-process buffer)
1068 (comint-check-proc buffer)
1069 (with-current-buffer buffer
1070 (and (derived-mode-p 'sql-product-interactive)
1071 (or (not product)
1072 (eq product sql-product)))))))
1073
1074 ;; Keymap for sql-interactive-mode.
1075
1076 (defvar sql-interactive-mode-map
1077 (let ((map (make-sparse-keymap)))
1078 (if (fboundp 'set-keymap-parent)
1079 (set-keymap-parent map comint-mode-map); Emacs
1080 (if (fboundp 'set-keymap-parents)
1081 (set-keymap-parents map (list comint-mode-map)))); XEmacs
1082 (if (fboundp 'set-keymap-name)
1083 (set-keymap-name map 'sql-interactive-mode-map)); XEmacs
1084 (define-key map (kbd "C-j") 'sql-accumulate-and-indent)
1085 (define-key map (kbd "C-c C-w") 'sql-copy-column)
1086 (define-key map (kbd "O") 'sql-magic-go)
1087 (define-key map (kbd "o") 'sql-magic-go)
1088 (define-key map (kbd ";") 'sql-magic-semicolon)
1089 map)
1090 "Mode map used for `sql-interactive-mode'.
1091 Based on `comint-mode-map'.")
1092
1093 ;; Keymap for sql-mode.
1094
1095 (defvar sql-mode-map
1096 (let ((map (make-sparse-keymap)))
1097 (define-key map (kbd "C-c C-c") 'sql-send-paragraph)
1098 (define-key map (kbd "C-c C-r") 'sql-send-region)
1099 (define-key map (kbd "C-c C-s") 'sql-send-string)
1100 (define-key map (kbd "C-c C-b") 'sql-send-buffer)
1101 (define-key map (kbd "C-c C-i") 'sql-product-interactive)
1102 map)
1103 "Mode map used for `sql-mode'.")
1104
1105 ;; easy menu for sql-mode.
1106
1107 (easy-menu-define
1108 sql-mode-menu sql-mode-map
1109 "Menu for `sql-mode'."
1110 `("SQL"
1111 ["Send Paragraph" sql-send-paragraph (sql-buffer-live-p sql-buffer)]
1112 ["Send Region" sql-send-region (and mark-active
1113 (sql-buffer-live-p sql-buffer))]
1114 ["Send Buffer" sql-send-buffer (sql-buffer-live-p sql-buffer)]
1115 ["Send String" sql-send-string (sql-buffer-live-p sql-buffer)]
1116 "--"
1117 ["Start SQLi session" sql-product-interactive
1118 :visible (not sql-connection-alist)
1119 :enable (sql-get-product-feature sql-product :sqli-comint-func)]
1120 ("Start..."
1121 :visible sql-connection-alist
1122 :filter sql-connection-menu-filter
1123 "--"
1124 ["New SQLi Session" sql-product-interactive (sql-get-product-feature sql-product :sqli-comint-func)])
1125 ["--"
1126 :visible sql-connection-alist]
1127 ["Show SQLi buffer" sql-show-sqli-buffer t]
1128 ["Set SQLi buffer" sql-set-sqli-buffer t]
1129 ["Pop to SQLi buffer after send"
1130 sql-toggle-pop-to-buffer-after-send-region
1131 :style toggle
1132 :selected sql-pop-to-buffer-after-send-region]
1133 ["--" nil nil]
1134 ("Product"
1135 ,@(mapcar (lambda (prod-info)
1136 (let* ((prod (pop prod-info))
1137 (name (or (plist-get prod-info :name)
1138 (capitalize (symbol-name prod))))
1139 (cmd (intern (format "sql-highlight-%s-keywords" prod))))
1140 (fset cmd `(lambda () ,(format "Highlight %s SQL keywords." name)
1141 (interactive)
1142 (sql-set-product ',prod)))
1143 (vector name cmd
1144 :style 'radio
1145 :selected `(eq sql-product ',prod))))
1146 sql-product-alist))))
1147
1148 ;; easy menu for sql-interactive-mode.
1149
1150 (easy-menu-define
1151 sql-interactive-mode-menu sql-interactive-mode-map
1152 "Menu for `sql-interactive-mode'."
1153 '("SQL"
1154 ["Rename Buffer" sql-rename-buffer t]
1155 ["Save Connection" sql-save-connection (not sql-connection)]))
1156
1157 ;; Abbreviations -- if you want more of them, define them in your
1158 ;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too.
1159
1160 (defvar sql-mode-abbrev-table nil
1161 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")
1162 (unless sql-mode-abbrev-table
1163 (define-abbrev-table 'sql-mode-abbrev-table nil))
1164
1165 (mapc
1166 ;; In Emacs 22+, provide SYSTEM-FLAG to define-abbrev.
1167 '(lambda (abbrev)
1168 (let ((name (car abbrev))
1169 (expansion (cdr abbrev)))
1170 (condition-case nil
1171 (define-abbrev sql-mode-abbrev-table name expansion nil 0 t)
1172 (error
1173 (define-abbrev sql-mode-abbrev-table name expansion)))))
1174 '(("ins" . "insert")
1175 ("upd" . "update")
1176 ("del" . "delete")
1177 ("sel" . "select")
1178 ("proc" . "procedure")
1179 ("func" . "function")
1180 ("cr" . "create")))
1181
1182 ;; Syntax Table
1183
1184 (defvar sql-mode-syntax-table
1185 (let ((table (make-syntax-table)))
1186 ;; C-style comments /**/ (see elisp manual "Syntax Flags"))
1187 (modify-syntax-entry ?/ ". 14" table)
1188 (modify-syntax-entry ?* ". 23" table)
1189 ;; double-dash starts comments
1190 (modify-syntax-entry ?- ". 12b" table)
1191 ;; newline and formfeed end comments
1192 (modify-syntax-entry ?\n "> b" table)
1193 (modify-syntax-entry ?\f "> b" table)
1194 ;; single quotes (') delimit strings
1195 (modify-syntax-entry ?' "\"" table)
1196 ;; double quotes (") don't delimit strings
1197 (modify-syntax-entry ?\" "." table)
1198 ;; backslash is no escape character
1199 (modify-syntax-entry ?\\ "." table)
1200 table)
1201 "Syntax table used in `sql-mode' and `sql-interactive-mode'.")
1202
1203 ;; Font lock support
1204
1205 (defvar sql-mode-font-lock-object-name
1206 (eval-when-compile
1207 (list (concat "^\\s-*\\(?:create\\|drop\\|alter\\)\\s-+" ;; lead off with CREATE, DROP or ALTER
1208 "\\(?:\\w+\\s-+\\)*" ;; optional intervening keywords
1209 "\\(?:table\\|view\\|\\(?:package\\|type\\)\\(?:\\s-+body\\)?\\|proc\\(?:edure\\)?"
1210 "\\|function\\|trigger\\|sequence\\|rule\\|default\\)\\s-+"
1211 "\\(\\w+\\)")
1212 1 'font-lock-function-name-face))
1213
1214 "Pattern to match the names of top-level objects.
1215
1216 The pattern matches the name in a CREATE, DROP or ALTER
1217 statement. The format of variable should be a valid
1218 `font-lock-keywords' entry.")
1219
1220 ;; While there are international and American standards for SQL, they
1221 ;; are not followed closely, and most vendors offer significant
1222 ;; capabilities beyond those defined in the standard specifications.
1223
1224 ;; SQL mode provides support for hilighting based on the product. In
1225 ;; addition to hilighting the product keywords, any ANSI keywords not
1226 ;; used by the product are also hilighted. This will help identify
1227 ;; keywords that could be restricted in future versions of the product
1228 ;; or might be a problem if ported to another product.
1229
1230 ;; To reduce the complexity and size of the regular expressions
1231 ;; generated to match keywords, ANSI keywords are filtered out of
1232 ;; product keywords if they are equivalent. To do this, we define a
1233 ;; function `sql-font-lock-keywords-builder' that removes any keywords
1234 ;; that are matched by the ANSI patterns and results in the same face
1235 ;; being applied. For this to work properly, we must play some games
1236 ;; with the execution and compile time behavior. This code is a
1237 ;; little tricky but works properly.
1238
1239 ;; When defining the keywords for individual products you should
1240 ;; include all of the keywords that you want matched. The filtering
1241 ;; against the ANSI keywords will be automatic if you use the
1242 ;; `sql-font-lock-keywords-builder' function and follow the
1243 ;; implementation pattern used for the other products in this file.
1244
1245 (eval-when-compile
1246 (defvar sql-mode-ansi-font-lock-keywords)
1247 (setq sql-mode-ansi-font-lock-keywords nil))
1248
1249 (eval-and-compile
1250 (defun sql-font-lock-keywords-builder (face boundaries &rest keywords)
1251 "Generation of regexp matching any one of KEYWORDS."
1252
1253 (let ((bdy (or boundaries '("\\b" . "\\b")))
1254 kwd)
1255
1256 ;; Remove keywords that are defined in ANSI
1257 (setq kwd keywords)
1258 (dolist (k keywords)
1259 (catch 'next
1260 (dolist (a sql-mode-ansi-font-lock-keywords)
1261 (when (and (eq face (cdr a))
1262 (eq (string-match (car a) k 0) 0)
1263 (eq (match-end 0) (length k)))
1264 (setq kwd (delq k kwd))
1265 (throw 'next nil)))))
1266
1267 ;; Create a properly formed font-lock-keywords item
1268 (cons (concat (car bdy)
1269 (regexp-opt kwd t)
1270 (cdr bdy))
1271 face))))
1272
1273 (eval-when-compile
1274 (setq sql-mode-ansi-font-lock-keywords
1275 (list
1276 ;; ANSI Non Reserved keywords
1277 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1278 "ada" "asensitive" "assignment" "asymmetric" "atomic" "between"
1279 "bitvar" "called" "catalog_name" "chain" "character_set_catalog"
1280 "character_set_name" "character_set_schema" "checked" "class_origin"
1281 "cobol" "collation_catalog" "collation_name" "collation_schema"
1282 "column_name" "command_function" "command_function_code" "committed"
1283 "condition_number" "connection_name" "constraint_catalog"
1284 "constraint_name" "constraint_schema" "contains" "cursor_name"
1285 "datetime_interval_code" "datetime_interval_precision" "defined"
1286 "definer" "dispatch" "dynamic_function" "dynamic_function_code"
1287 "existing" "exists" "final" "fortran" "generated" "granted"
1288 "hierarchy" "hold" "implementation" "infix" "insensitive" "instance"
1289 "instantiable" "invoker" "key_member" "key_type" "length" "m"
1290 "message_length" "message_octet_length" "message_text" "method" "more"
1291 "mumps" "name" "nullable" "number" "options" "overlaps" "overriding"
1292 "parameter_mode" "parameter_name" "parameter_ordinal_position"
1293 "parameter_specific_catalog" "parameter_specific_name"
1294 "parameter_specific_schema" "pascal" "pli" "position" "repeatable"
1295 "returned_length" "returned_octet_length" "returned_sqlstate"
1296 "routine_catalog" "routine_name" "routine_schema" "row_count" "scale"
1297 "schema_name" "security" "self" "sensitive" "serializable"
1298 "server_name" "similar" "simple" "source" "specific_name" "style"
1299 "subclass_origin" "sublist" "symmetric" "system" "table_name"
1300 "transaction_active" "transactions_committed"
1301 "transactions_rolled_back" "transform" "transforms" "trigger_catalog"
1302 "trigger_name" "trigger_schema" "type" "uncommitted" "unnamed"
1303 "user_defined_type_catalog" "user_defined_type_name"
1304 "user_defined_type_schema"
1305 )
1306 ;; ANSI Reserved keywords
1307 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1308 "absolute" "action" "add" "admin" "after" "aggregate" "alias" "all"
1309 "allocate" "alter" "and" "any" "are" "as" "asc" "assertion" "at"
1310 "authorization" "before" "begin" "both" "breadth" "by" "call"
1311 "cascade" "cascaded" "case" "catalog" "check" "class" "close"
1312 "collate" "collation" "column" "commit" "completion" "connect"
1313 "connection" "constraint" "constraints" "constructor" "continue"
1314 "corresponding" "create" "cross" "cube" "current" "cursor" "cycle"
1315 "data" "day" "deallocate" "declare" "default" "deferrable" "deferred"
1316 "delete" "depth" "deref" "desc" "describe" "descriptor" "destroy"
1317 "destructor" "deterministic" "diagnostics" "dictionary" "disconnect"
1318 "distinct" "domain" "drop" "dynamic" "each" "else" "end" "equals"
1319 "escape" "every" "except" "exception" "exec" "execute" "external"
1320 "false" "fetch" "first" "for" "foreign" "found" "free" "from" "full"
1321 "function" "general" "get" "global" "go" "goto" "grant" "group"
1322 "grouping" "having" "host" "hour" "identity" "ignore" "immediate" "in"
1323 "indicator" "initialize" "initially" "inner" "inout" "input" "insert"
1324 "intersect" "into" "is" "isolation" "iterate" "join" "key" "language"
1325 "last" "lateral" "leading" "left" "less" "level" "like" "limit"
1326 "local" "locator" "map" "match" "minute" "modifies" "modify" "module"
1327 "month" "names" "natural" "new" "next" "no" "none" "not" "null" "of"
1328 "off" "old" "on" "only" "open" "operation" "option" "or" "order"
1329 "ordinality" "out" "outer" "output" "pad" "parameter" "parameters"
1330 "partial" "path" "postfix" "prefix" "preorder" "prepare" "preserve"
1331 "primary" "prior" "privileges" "procedure" "public" "read" "reads"
1332 "recursive" "references" "referencing" "relative" "restrict" "result"
1333 "return" "returns" "revoke" "right" "role" "rollback" "rollup"
1334 "routine" "rows" "savepoint" "schema" "scroll" "search" "second"
1335 "section" "select" "sequence" "session" "set" "sets" "size" "some"
1336 "space" "specific" "specifictype" "sql" "sqlexception" "sqlstate"
1337 "sqlwarning" "start" "state" "statement" "static" "structure" "table"
1338 "temporary" "terminate" "than" "then" "timezone_hour"
1339 "timezone_minute" "to" "trailing" "transaction" "translation"
1340 "trigger" "true" "under" "union" "unique" "unknown" "unnest" "update"
1341 "usage" "using" "value" "values" "variable" "view" "when" "whenever"
1342 "where" "with" "without" "work" "write" "year"
1343 )
1344
1345 ;; ANSI Functions
1346 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1347 "abs" "avg" "bit_length" "cardinality" "cast" "char_length"
1348 "character_length" "coalesce" "convert" "count" "current_date"
1349 "current_path" "current_role" "current_time" "current_timestamp"
1350 "current_user" "extract" "localtime" "localtimestamp" "lower" "max"
1351 "min" "mod" "nullif" "octet_length" "overlay" "placing" "session_user"
1352 "substring" "sum" "system_user" "translate" "treat" "trim" "upper"
1353 "user"
1354 )
1355 ;; ANSI Data Types
1356 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1357 "array" "binary" "bit" "blob" "boolean" "char" "character" "clob"
1358 "date" "dec" "decimal" "double" "float" "int" "integer" "interval"
1359 "large" "national" "nchar" "nclob" "numeric" "object" "precision"
1360 "real" "ref" "row" "scope" "smallint" "time" "timestamp" "varchar"
1361 "varying" "zone"
1362 ))))
1363
1364 (defvar sql-mode-ansi-font-lock-keywords
1365 (eval-when-compile sql-mode-ansi-font-lock-keywords)
1366 "ANSI SQL keywords used by font-lock.
1367
1368 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1369 regular expressions are created during compilation by calling the
1370 function `regexp-opt'. Therefore, take a look at the source before
1371 you define your own `sql-mode-ansi-font-lock-keywords'. You may want
1372 to add functions and PL/SQL keywords.")
1373
1374 (defvar sql-mode-oracle-font-lock-keywords
1375 (eval-when-compile
1376 (list
1377 ;; Oracle SQL*Plus Commands
1378 (cons
1379 (concat
1380 "^\\s-*\\(?:\\(?:" (regexp-opt '(
1381 "@" "@@" "accept" "append" "archive" "attribute" "break"
1382 "btitle" "change" "clear" "column" "connect" "copy" "define"
1383 "del" "describe" "disconnect" "edit" "execute" "exit" "get" "help"
1384 "host" "input" "list" "password" "pause" "print" "prompt" "recover"
1385 "remark" "repfooter" "repheader" "run" "save" "show" "shutdown"
1386 "spool" "start" "startup" "store" "timing" "ttitle" "undefine"
1387 "variable" "whenever"
1388 ) t)
1389
1390 "\\)\\|"
1391 "\\(?:compute\\s-+\\(?:avg\\|cou\\|min\\|max\\|num\\|sum\\|std\\|var\\)\\)\\|"
1392 "\\(?:set\\s-+\\("
1393
1394 (regexp-opt
1395 '("appi" "appinfo" "array" "arraysize" "auto" "autocommit"
1396 "autop" "autoprint" "autorecovery" "autot" "autotrace" "blo"
1397 "blockterminator" "buffer" "closecursor" "cmds" "cmdsep"
1398 "colsep" "com" "compatibility" "con" "concat" "constraint"
1399 "constraints" "copyc" "copycommit" "copytypecheck" "database"
1400 "def" "define" "document" "echo" "editf" "editfile" "emb"
1401 "embedded" "esc" "escape" "feed" "feedback" "flagger" "flu"
1402 "flush" "hea" "heading" "heads" "headsep" "instance" "lin"
1403 "linesize" "lobof" "loboffset" "logsource" "long" "longc"
1404 "longchunksize" "maxdata" "newp" "newpage" "null" "num"
1405 "numf" "numformat" "numwidth" "pages" "pagesize" "pau"
1406 "pause" "recsep" "recsepchar" "role" "scan" "serveroutput"
1407 "shift" "shiftinout" "show" "showmode" "space" "sqlbl"
1408 "sqlblanklines" "sqlc" "sqlcase" "sqlco" "sqlcontinue" "sqln"
1409 "sqlnumber" "sqlp" "sqlpluscompat" "sqlpluscompatibility"
1410 "sqlpre" "sqlprefix" "sqlprompt" "sqlt" "sqlterminator"
1411 "statement_id" "suf" "suffix" "tab" "term" "termout" "ti"
1412 "time" "timi" "timing" "transaction" "trim" "trimout" "trims"
1413 "trimspool" "truncate" "und" "underline" "ver" "verify" "wra"
1414 "wrap")) "\\)\\)"
1415
1416 "\\)\\b.*"
1417 )
1418 'font-lock-doc-face)
1419 '("^\\s-*rem\\(?:ark\\)?\\>.*" . font-lock-comment-face)
1420
1421 ;; Oracle Functions
1422 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1423 "abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2"
1424 "avg" "bfilename" "bin_to_num" "bitand" "cast" "ceil" "chartorowid"
1425 "chr" "coalesce" "compose" "concat" "convert" "corr" "cos" "cosh"
1426 "count" "covar_pop" "covar_samp" "cume_dist" "current_date"
1427 "current_timestamp" "current_user" "dbtimezone" "decode" "decompose"
1428 "dense_rank" "depth" "deref" "dump" "empty_clob" "existsnode" "exp"
1429 "extract" "extractvalue" "first" "first_value" "floor" "following"
1430 "from_tz" "greatest" "group_id" "grouping_id" "hextoraw" "initcap"
1431 "instr" "lag" "last" "last_day" "last_value" "lead" "least" "length"
1432 "ln" "localtimestamp" "lower" "lpad" "ltrim" "make_ref" "max" "min"
1433 "mod" "months_between" "new_time" "next_day" "nls_charset_decl_len"
1434 "nls_charset_id" "nls_charset_name" "nls_initcap" "nls_lower"
1435 "nls_upper" "nlssort" "ntile" "nullif" "numtodsinterval"
1436 "numtoyminterval" "nvl" "nvl2" "over" "path" "percent_rank"
1437 "percentile_cont" "percentile_disc" "power" "preceding" "rank"
1438 "ratio_to_report" "rawtohex" "rawtonhex" "reftohex" "regr_"
1439 "regr_avgx" "regr_avgy" "regr_count" "regr_intercept" "regr_r2"
1440 "regr_slope" "regr_sxx" "regr_sxy" "regr_syy" "replace" "round"
1441 "row_number" "rowidtochar" "rowidtonchar" "rpad" "rtrim"
1442 "sessiontimezone" "sign" "sin" "sinh" "soundex" "sqrt" "stddev"
1443 "stddev_pop" "stddev_samp" "substr" "sum" "sys_connect_by_path"
1444 "sys_context" "sys_dburigen" "sys_extract_utc" "sys_guid" "sys_typeid"
1445 "sys_xmlagg" "sys_xmlgen" "sysdate" "systimestamp" "tan" "tanh"
1446 "to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte"
1447 "to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp"
1448 "to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc"
1449 "tz_offset" "uid" "unbounded" "unistr" "updatexml" "upper" "user"
1450 "userenv" "var_pop" "var_samp" "variance" "vsize" "width_bucket" "xml"
1451 "xmlagg" "xmlattribute" "xmlcolattval" "xmlconcat" "xmlelement"
1452 "xmlforest" "xmlsequence" "xmltransform"
1453 )
1454 ;; Oracle Keywords
1455 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1456 "abort" "access" "accessed" "account" "activate" "add" "admin"
1457 "advise" "after" "agent" "aggregate" "all" "allocate" "allow" "alter"
1458 "always" "analyze" "ancillary" "and" "any" "apply" "archive"
1459 "archivelog" "array" "as" "asc" "associate" "at" "attribute"
1460 "attributes" "audit" "authenticated" "authid" "authorization" "auto"
1461 "autoallocate" "automatic" "availability" "backup" "before" "begin"
1462 "behalf" "between" "binding" "bitmap" "block" "blocksize" "body"
1463 "both" "buffer_pool" "build" "by" "cache" "call" "cancel"
1464 "cascade" "case" "category" "certificate" "chained" "change" "check"
1465 "checkpoint" "child" "chunk" "class" "clear" "clone" "close" "cluster"
1466 "column" "column_value" "columns" "comment" "commit" "committed"
1467 "compatibility" "compile" "complete" "composite_limit" "compress"
1468 "compute" "connect" "connect_time" "consider" "consistent"
1469 "constraint" "constraints" "constructor" "contents" "context"
1470 "continue" "controlfile" "corruption" "cost" "cpu_per_call"
1471 "cpu_per_session" "create" "cross" "cube" "current" "currval" "cycle"
1472 "dangling" "data" "database" "datafile" "datafiles" "day" "ddl"
1473 "deallocate" "debug" "default" "deferrable" "deferred" "definer"
1474 "delay" "delete" "demand" "desc" "determines" "deterministic"
1475 "dictionary" "dimension" "directory" "disable" "disassociate"
1476 "disconnect" "distinct" "distinguished" "distributed" "dml" "drop"
1477 "each" "element" "else" "enable" "end" "equals_path" "escape"
1478 "estimate" "except" "exceptions" "exchange" "excluding" "exists"
1479 "expire" "explain" "extent" "external" "externally"
1480 "failed_login_attempts" "fast" "file" "final" "finish" "flush" "for"
1481 "force" "foreign" "freelist" "freelists" "freepools" "fresh" "from"
1482 "full" "function" "functions" "generated" "global" "global_name"
1483 "globally" "grant" "group" "grouping" "groups" "guard" "hash"
1484 "hashkeys" "having" "heap" "hierarchy" "id" "identified" "identifier"
1485 "idle_time" "immediate" "in" "including" "increment" "index" "indexed"
1486 "indexes" "indextype" "indextypes" "indicator" "initial" "initialized"
1487 "initially" "initrans" "inner" "insert" "instance" "instantiable"
1488 "instead" "intersect" "into" "invalidate" "is" "isolation" "java"
1489 "join" "keep" "key" "kill" "language" "left" "less" "level"
1490 "levels" "library" "like" "like2" "like4" "likec" "limit" "link"
1491 "list" "lob" "local" "location" "locator" "lock" "log" "logfile"
1492 "logging" "logical" "logical_reads_per_call"
1493 "logical_reads_per_session" "managed" "management" "manual" "map"
1494 "mapping" "master" "matched" "materialized" "maxdatafiles"
1495 "maxextents" "maximize" "maxinstances" "maxlogfiles" "maxloghistory"
1496 "maxlogmembers" "maxsize" "maxtrans" "maxvalue" "member" "memory"
1497 "merge" "migrate" "minextents" "minimize" "minimum" "minus" "minvalue"
1498 "mode" "modify" "monitoring" "month" "mount" "move" "movement" "name"
1499 "named" "natural" "nested" "never" "new" "next" "nextval" "no"
1500 "noarchivelog" "noaudit" "nocache" "nocompress" "nocopy" "nocycle"
1501 "nodelay" "noforce" "nologging" "nomapping" "nomaxvalue" "nominimize"
1502 "nominvalue" "nomonitoring" "none" "noorder" "noparallel" "norely"
1503 "noresetlogs" "noreverse" "normal" "norowdependencies" "nosort"
1504 "noswitch" "not" "nothing" "notimeout" "novalidate" "nowait" "null"
1505 "nulls" "object" "of" "off" "offline" "oidindex" "old" "on" "online"
1506 "only" "open" "operator" "optimal" "option" "or" "order"
1507 "organization" "out" "outer" "outline" "overflow" "overriding"
1508 "package" "packages" "parallel" "parallel_enable" "parameters"
1509 "parent" "partition" "partitions" "password" "password_grace_time"
1510 "password_life_time" "password_lock_time" "password_reuse_max"
1511 "password_reuse_time" "password_verify_function" "pctfree"
1512 "pctincrease" "pctthreshold" "pctused" "pctversion" "percent"
1513 "performance" "permanent" "pfile" "physical" "pipelined" "plan"
1514 "post_transaction" "pragma" "prebuilt" "preserve" "primary" "private"
1515 "private_sga" "privileges" "procedure" "profile" "protection" "public"
1516 "purge" "query" "quiesce" "quota" "range" "read" "reads" "rebuild"
1517 "records_per_block" "recover" "recovery" "recycle" "reduced" "ref"
1518 "references" "referencing" "refresh" "register" "reject" "relational"
1519 "rely" "rename" "reset" "resetlogs" "resize" "resolve" "resolver"
1520 "resource" "restrict" "restrict_references" "restricted" "result"
1521 "resumable" "resume" "retention" "return" "returning" "reuse"
1522 "reverse" "revoke" "rewrite" "right" "rnds" "rnps" "role" "roles"
1523 "rollback" "rollup" "row" "rowdependencies" "rownum" "rows" "sample"
1524 "savepoint" "scan" "schema" "scn" "scope" "segment" "select"
1525 "selectivity" "self" "sequence" "serializable" "session"
1526 "sessions_per_user" "set" "sets" "settings" "shared" "shared_pool"
1527 "shrink" "shutdown" "siblings" "sid" "single" "size" "skip" "some"
1528 "sort" "source" "space" "specification" "spfile" "split" "standby"
1529 "start" "statement_id" "static" "statistics" "stop" "storage" "store"
1530 "structure" "subpartition" "subpartitions" "substitutable"
1531 "successful" "supplemental" "suspend" "switch" "switchover" "synonym"
1532 "sys" "system" "table" "tables" "tablespace" "tempfile" "template"
1533 "temporary" "test" "than" "then" "thread" "through" "time_zone"
1534 "timeout" "to" "trace" "transaction" "trigger" "triggers" "truncate"
1535 "trust" "type" "types" "unarchived" "under" "under_path" "undo"
1536 "uniform" "union" "unique" "unlimited" "unlock" "unquiesce"
1537 "unrecoverable" "until" "unusable" "unused" "update" "upgrade" "usage"
1538 "use" "using" "validate" "validation" "value" "values" "variable"
1539 "varray" "version" "view" "wait" "when" "whenever" "where" "with"
1540 "without" "wnds" "wnps" "work" "write" "xmldata" "xmlschema" "xmltype"
1541 )
1542 ;; Oracle Data Types
1543 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1544 "bfile" "blob" "byte" "char" "character" "clob" "date" "dec" "decimal"
1545 "double" "float" "int" "integer" "interval" "long" "national" "nchar"
1546 "nclob" "number" "numeric" "nvarchar2" "precision" "raw" "real"
1547 "rowid" "second" "smallint" "time" "timestamp" "urowid" "varchar"
1548 "varchar2" "varying" "year" "zone"
1549 )
1550
1551 ;; Oracle PL/SQL Attributes
1552 (sql-font-lock-keywords-builder 'font-lock-builtin-face '("" . "\\b")
1553 "%bulk_rowcount" "%found" "%isopen" "%notfound" "%rowcount" "%rowtype"
1554 "%type"
1555 )
1556
1557 ;; Oracle PL/SQL Functions
1558 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1559 "extend" "prior"
1560 )
1561
1562 ;; Oracle PL/SQL Keywords
1563 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1564 "autonomous_transaction" "bulk" "char_base" "collect" "constant"
1565 "cursor" "declare" "do" "elsif" "exception_init" "execute" "exit"
1566 "extends" "false" "fetch" "forall" "goto" "hour" "if" "interface"
1567 "loop" "minute" "number_base" "ocirowid" "opaque" "others" "rowtype"
1568 "separate" "serially_reusable" "sql" "sqlcode" "sqlerrm" "subtype"
1569 "the" "timezone_abbr" "timezone_hour" "timezone_minute"
1570 "timezone_region" "true" "varrying" "while"
1571 )
1572
1573 ;; Oracle PL/SQL Data Types
1574 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1575 "binary_integer" "boolean" "naturaln" "pls_integer" "positive"
1576 "positiven" "record" "signtype" "string"
1577 )
1578
1579 ;; Oracle PL/SQL Exceptions
1580 (sql-font-lock-keywords-builder 'font-lock-warning-face nil
1581 "access_into_null" "case_not_found" "collection_is_null"
1582 "cursor_already_open" "dup_val_on_index" "invalid_cursor"
1583 "invalid_number" "login_denied" "no_data_found" "not_logged_on"
1584 "program_error" "rowtype_mismatch" "self_is_null" "storage_error"
1585 "subscript_beyond_count" "subscript_outside_limit" "sys_invalid_rowid"
1586 "timeout_on_resource" "too_many_rows" "value_error" "zero_divide"
1587 "exception" "notfound"
1588 )))
1589
1590 "Oracle SQL keywords used by font-lock.
1591
1592 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1593 regular expressions are created during compilation by calling the
1594 function `regexp-opt'. Therefore, take a look at the source before
1595 you define your own `sql-mode-oracle-font-lock-keywords'. You may want
1596 to add functions and PL/SQL keywords.")
1597
1598 (defvar sql-mode-postgres-font-lock-keywords
1599 (eval-when-compile
1600 (list
1601 ;; Postgres psql commands
1602 '("^\\s-*\\\\.*$" . font-lock-doc-face)
1603
1604 ;; Postgres unreserved words but may have meaning
1605 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil "a"
1606 "abs" "absent" "according" "ada" "alias" "allocate" "are" "array_agg"
1607 "asensitive" "atomic" "attribute" "attributes" "avg" "base64"
1608 "bernoulli" "bit_length" "bitvar" "blob" "blocked" "bom" "breadth" "c"
1609 "call" "cardinality" "catalog_name" "ceil" "ceiling" "char_length"
1610 "character_length" "character_set_catalog" "character_set_name"
1611 "character_set_schema" "characters" "checked" "class_origin" "clob"
1612 "cobol" "collation" "collation_catalog" "collation_name"
1613 "collation_schema" "collect" "column_name" "columns"
1614 "command_function" "command_function_code" "completion" "condition"
1615 "condition_number" "connect" "connection_name" "constraint_catalog"
1616 "constraint_name" "constraint_schema" "constructor" "contains"
1617 "control" "convert" "corr" "corresponding" "count" "covar_pop"
1618 "covar_samp" "cube" "cume_dist" "current_default_transform_group"
1619 "current_path" "current_transform_group_for_type" "cursor_name"
1620 "datalink" "datetime_interval_code" "datetime_interval_precision" "db"
1621 "defined" "degree" "dense_rank" "depth" "deref" "derived" "describe"
1622 "descriptor" "destroy" "destructor" "deterministic" "diagnostics"
1623 "disconnect" "dispatch" "dlnewcopy" "dlpreviouscopy" "dlurlcomplete"
1624 "dlurlcompleteonly" "dlurlcompletewrite" "dlurlpath" "dlurlpathonly"
1625 "dlurlpathwrite" "dlurlscheme" "dlurlserver" "dlvalue" "dynamic"
1626 "dynamic_function" "dynamic_function_code" "element" "empty"
1627 "end-exec" "equals" "every" "exception" "exec" "existing" "exp" "file"
1628 "filter" "final" "first_value" "flag" "floor" "fortran" "found" "free"
1629 "fs" "fusion" "g" "general" "generated" "get" "go" "goto" "grouping"
1630 "hex" "hierarchy" "host" "id" "ignore" "implementation" "import"
1631 "indent" "indicator" "infix" "initialize" "instance" "instantiable"
1632 "integrity" "intersection" "iterate" "k" "key_member" "key_type" "lag"
1633 "last_value" "lateral" "lead" "length" "less" "library" "like_regex"
1634 "link" "ln" "locator" "lower" "m" "map" "matched" "max"
1635 "max_cardinality" "member" "merge" "message_length"
1636 "message_octet_length" "message_text" "method" "min" "mod" "modifies"
1637 "modify" "module" "more" "multiset" "mumps" "namespace" "nclob"
1638 "nesting" "new" "nfc" "nfd" "nfkc" "nfkd" "nil" "normalize"
1639 "normalized" "nth_value" "ntile" "nullable" "number"
1640 "occurrences_regex" "octet_length" "octets" "old" "open" "operation"
1641 "ordering" "ordinality" "others" "output" "overriding" "p" "pad"
1642 "parameter" "parameter_mode" "parameter_name"
1643 "parameter_ordinal_position" "parameter_specific_catalog"
1644 "parameter_specific_name" "parameter_specific_schema" "parameters"
1645 "pascal" "passing" "passthrough" "percent_rank" "percentile_cont"
1646 "percentile_disc" "permission" "pli" "position_regex" "postfix"
1647 "power" "prefix" "preorder" "public" "rank" "reads" "recovery" "ref"
1648 "referencing" "regr_avgx" "regr_avgy" "regr_count" "regr_intercept"
1649 "regr_r2" "regr_slope" "regr_sxx" "regr_sxy" "regr_syy" "requiring"
1650 "respect" "restore" "result" "return" "returned_cardinality"
1651 "returned_length" "returned_octet_length" "returned_sqlstate" "rollup"
1652 "routine" "routine_catalog" "routine_name" "routine_schema"
1653 "row_count" "row_number" "scale" "schema_name" "scope" "scope_catalog"
1654 "scope_name" "scope_schema" "section" "selective" "self" "sensitive"
1655 "server_name" "sets" "size" "source" "space" "specific"
1656 "specific_name" "specifictype" "sql" "sqlcode" "sqlerror"
1657 "sqlexception" "sqlstate" "sqlwarning" "sqrt" "state" "static"
1658 "stddev_pop" "stddev_samp" "structure" "style" "subclass_origin"
1659 "sublist" "submultiset" "substring_regex" "sum" "system_user" "t"
1660 "table_name" "tablesample" "terminate" "than" "ties" "timezone_hour"
1661 "timezone_minute" "token" "top_level_count" "transaction_active"
1662 "transactions_committed" "transactions_rolled_back" "transform"
1663 "transforms" "translate" "translate_regex" "translation"
1664 "trigger_catalog" "trigger_name" "trigger_schema" "trim_array"
1665 "uescape" "under" "unlink" "unnamed" "unnest" "untyped" "upper" "uri"
1666 "usage" "user_defined_type_catalog" "user_defined_type_code"
1667 "user_defined_type_name" "user_defined_type_schema" "var_pop"
1668 "var_samp" "varbinary" "variable" "whenever" "width_bucket" "within"
1669 "xmlagg" "xmlbinary" "xmlcast" "xmlcomment" "xmldeclaration"
1670 "xmldocument" "xmlexists" "xmliterate" "xmlnamespaces" "xmlquery"
1671 "xmlschema" "xmltable" "xmltext" "xmlvalidate"
1672 )
1673
1674 ;; Postgres non-reserved words
1675 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1676 "abort" "absolute" "access" "action" "add" "admin" "after" "aggregate"
1677 "also" "alter" "always" "assertion" "assignment" "at" "backward"
1678 "before" "begin" "between" "by" "cache" "called" "cascade" "cascaded"
1679 "catalog" "chain" "characteristics" "checkpoint" "class" "close"
1680 "cluster" "coalesce" "comment" "comments" "commit" "committed"
1681 "configuration" "connection" "constraints" "content" "continue"
1682 "conversion" "copy" "cost" "createdb" "createrole" "createuser" "csv"
1683 "current" "cursor" "cycle" "data" "database" "day" "deallocate" "dec"
1684 "declare" "defaults" "deferred" "definer" "delete" "delimiter"
1685 "delimiters" "dictionary" "disable" "discard" "document" "domain"
1686 "drop" "each" "enable" "encoding" "encrypted" "enum" "escape"
1687 "exclude" "excluding" "exclusive" "execute" "exists" "explain"
1688 "external" "extract" "family" "first" "float" "following" "force"
1689 "forward" "function" "functions" "global" "granted" "greatest"
1690 "handler" "header" "hold" "hour" "identity" "if" "immediate"
1691 "immutable" "implicit" "including" "increment" "index" "indexes"
1692 "inherit" "inherits" "inline" "inout" "input" "insensitive" "insert"
1693 "instead" "invoker" "isolation" "key" "language" "large" "last"
1694 "lc_collate" "lc_ctype" "least" "level" "listen" "load" "local"
1695 "location" "lock" "login" "mapping" "match" "maxvalue" "minute"
1696 "minvalue" "mode" "month" "move" "name" "names" "national" "nchar"
1697 "next" "no" "nocreatedb" "nocreaterole" "nocreateuser" "noinherit"
1698 "nologin" "none" "nosuperuser" "nothing" "notify" "nowait" "nullif"
1699 "nulls" "object" "of" "oids" "operator" "option" "options" "out"
1700 "overlay" "owned" "owner" "parser" "partial" "partition" "password"
1701 "plans" "position" "preceding" "prepare" "prepared" "preserve" "prior"
1702 "privileges" "procedural" "procedure" "quote" "range" "read"
1703 "reassign" "recheck" "recursive" "reindex" "relative" "release"
1704 "rename" "repeatable" "replace" "replica" "reset" "restart" "restrict"
1705 "returns" "revoke" "role" "rollback" "row" "rows" "rule" "savepoint"
1706 "schema" "scroll" "search" "second" "security" "sequence" "sequences"
1707 "serializable" "server" "session" "set" "setof" "share" "show"
1708 "simple" "stable" "standalone" "start" "statement" "statistics"
1709 "stdin" "stdout" "storage" "strict" "strip" "substring" "superuser"
1710 "sysid" "system" "tables" "tablespace" "temp" "template" "temporary"
1711 "transaction" "treat" "trigger" "trim" "truncate" "trusted" "type"
1712 "unbounded" "uncommitted" "unencrypted" "unknown" "unlisten" "until"
1713 "update" "vacuum" "valid" "validator" "value" "values" "version"
1714 "view" "volatile" "whitespace" "work" "wrapper" "write"
1715 "xmlattributes" "xmlconcat" "xmlelement" "xmlforest" "xmlparse"
1716 "xmlpi" "xmlroot" "xmlserialize" "year" "yes"
1717 )
1718
1719 ;; Postgres Reserved
1720 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1721 "all" "analyse" "analyze" "and" "any" "array" "asc" "as" "asymmetric"
1722 "authorization" "binary" "both" "case" "cast" "check" "collate"
1723 "column" "concurrently" "constraint" "create" "cross"
1724 "current_catalog" "current_date" "current_role" "current_schema"
1725 "current_time" "current_timestamp" "current_user" "default"
1726 "deferrable" "desc" "distinct" "do" "else" "end" "except" "false"
1727 "fetch" "foreign" "for" "freeze" "from" "full" "grant" "group"
1728 "having" "ilike" "initially" "inner" "in" "intersect" "into" "isnull"
1729 "is" "join" "leading" "left" "like" "limit" "localtime"
1730 "localtimestamp" "natural" "notnull" "not" "null" "off" "offset"
1731 "only" "on" "order" "or" "outer" "overlaps" "over" "placing" "primary"
1732 "references" "returning" "right" "select" "session_user" "similar"
1733 "some" "symmetric" "table" "then" "to" "trailing" "true" "union"
1734 "unique" "user" "using" "variadic" "verbose" "when" "where" "window"
1735 "with"
1736 )
1737
1738 ;; Postgres Data Types
1739 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1740 "bigint" "bigserial" "bit" "bool" "boolean" "box" "bytea" "char"
1741 "character" "cidr" "circle" "date" "decimal" "double" "float4"
1742 "float8" "inet" "int" "int2" "int4" "int8" "integer" "interval" "line"
1743 "lseg" "macaddr" "money" "numeric" "path" "point" "polygon"
1744 "precision" "real" "serial" "serial4" "serial8" "smallint" "text"
1745 "time" "timestamp" "timestamptz" "timetz" "tsquery" "tsvector"
1746 "txid_snapshot" "uuid" "varbit" "varchar" "varying" "without"
1747 "xml" "zone"
1748 )))
1749
1750 "Postgres SQL keywords used by font-lock.
1751
1752 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1753 regular expressions are created during compilation by calling the
1754 function `regexp-opt'. Therefore, take a look at the source before
1755 you define your own `sql-mode-postgres-font-lock-keywords'.")
1756
1757 (defvar sql-mode-linter-font-lock-keywords
1758 (eval-when-compile
1759 (list
1760 ;; Linter Keywords
1761 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1762 "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel"
1763 "committed" "count" "countblob" "cross" "current" "data" "database"
1764 "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred"
1765 "denied" "description" "device" "difference" "directory" "error"
1766 "escape" "euc" "exclusive" "external" "extfile" "false" "file"
1767 "filename" "filesize" "filetime" "filter" "findblob" "first" "foreign"
1768 "full" "fuzzy" "global" "granted" "ignore" "immediate" "increment"
1769 "indexes" "indexfile" "indexfiles" "indextime" "initial" "integrity"
1770 "internal" "key" "last_autoinc" "last_rowid" "limit" "linter"
1771 "linter_file_device" "linter_file_size" "linter_name_length" "ln"
1772 "local" "login" "maxisn" "maxrow" "maxrowid" "maxvalue" "message"
1773 "minvalue" "module" "names" "national" "natural" "new" "new_table"
1774 "no" "node" "noneuc" "nulliferror" "numbers" "off" "old" "old_table"
1775 "only" "operation" "optimistic" "option" "page" "partially" "password"
1776 "phrase" "plan" "precision" "primary" "priority" "privileges"
1777 "proc_info_size" "proc_par_name_len" "protocol" "quant" "range" "raw"
1778 "read" "record" "records" "references" "remote" "rename" "replication"
1779 "restart" "rewrite" "root" "row" "rule" "savepoint" "security"
1780 "sensitive" "sequence" "serializable" "server" "since" "size" "some"
1781 "startup" "statement" "station" "success" "sys_guid" "tables" "test"
1782 "timeout" "trace" "transaction" "translation" "trigger"
1783 "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown"
1784 "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes"
1785 "wait" "windows_code" "workspace" "write" "xml"
1786 )
1787
1788 ;; Linter Reserved
1789 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1790 "access" "action" "add" "address" "after" "all" "alter" "always" "and"
1791 "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit"
1792 "aud_obj_name_len" "backup" "base" "before" "between" "blobfile"
1793 "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check"
1794 "clear" "close" "column" "comment" "commit" "connect" "contains"
1795 "correct" "create" "delete" "desc" "disable" "disconnect" "distinct"
1796 "drop" "each" "ef" "else" "enable" "end" "event" "except" "exclude"
1797 "execute" "exists" "extract" "fetch" "finish" "for" "from" "get"
1798 "grant" "group" "having" "identified" "in" "index" "inner" "insert"
1799 "instead" "intersect" "into" "is" "isolation" "join" "left" "level"
1800 "like" "lock" "mode" "modify" "not" "nowait" "null" "of" "on" "open"
1801 "or" "order" "outer" "owner" "press" "prior" "procedure" "public"
1802 "purge" "rebuild" "resource" "restrict" "revoke" "right" "role"
1803 "rollback" "rownum" "select" "session" "set" "share" "shutdown"
1804 "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then"
1805 "to" "union" "unique" "unlock" "until" "update" "using" "values"
1806 "view" "when" "where" "with" "without"
1807 )
1808
1809 ;; Linter Functions
1810 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1811 "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime"
1812 "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw"
1813 "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log"
1814 "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl"
1815 "octet_length" "power" "rand" "rawtohex" "repeat_string"
1816 "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex"
1817 "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date"
1818 "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode"
1819 "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap"
1820 "instr" "least" "multime" "replace" "width"
1821 )
1822
1823 ;; Linter Data Types
1824 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1825 "bigint" "bitmap" "blob" "boolean" "char" "character" "date"
1826 "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar"
1827 "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte"
1828 "cursor" "long"
1829 )))
1830
1831 "Linter SQL keywords used by font-lock.
1832
1833 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1834 regular expressions are created during compilation by calling the
1835 function `regexp-opt'.")
1836
1837 (defvar sql-mode-ms-font-lock-keywords
1838 (eval-when-compile
1839 (list
1840 ;; MS isql/osql Commands
1841 (cons
1842 (concat
1843 "^\\(?:\\(?:set\\s-+\\(?:"
1844 (regexp-opt '(
1845 "datefirst" "dateformat" "deadlock_priority" "lock_timeout"
1846 "concat_null_yields_null" "cursor_close_on_commit"
1847 "disable_def_cnst_chk" "fips_flagger" "identity_insert" "language"
1848 "offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly"
1849 "nocount" "noexec" "numeric_roundabort" "parseonly"
1850 "query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults"
1851 "ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding"
1852 "ansi_warnings" "forceplan" "showplan_all" "showplan_text"
1853 "statistics" "implicit_transactions" "remote_proc_transactions"
1854 "transaction" "xact_abort"
1855 ) t)
1856 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$")
1857 'font-lock-doc-face)
1858
1859 ;; MS Reserved
1860 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1861 "absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization"
1862 "avg" "backup" "begin" "between" "break" "browse" "bulk" "by"
1863 "cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce"
1864 "column" "commit" "committed" "compute" "confirm" "constraint"
1865 "contains" "containstable" "continue" "controlrow" "convert" "count"
1866 "create" "cross" "current" "current_date" "current_time"
1867 "current_timestamp" "current_user" "database" "deallocate" "declare"
1868 "default" "delete" "deny" "desc" "disk" "distinct" "distributed"
1869 "double" "drop" "dummy" "dump" "else" "end" "errlvl" "errorexit"
1870 "escape" "except" "exec" "execute" "exists" "exit" "fetch" "file"
1871 "fillfactor" "first" "floppy" "for" "foreign" "freetext"
1872 "freetexttable" "from" "full" "goto" "grant" "group" "having"
1873 "holdlock" "identity" "identity_insert" "identitycol" "if" "in"
1874 "index" "inner" "insert" "intersect" "into" "is" "isolation" "join"
1875 "key" "kill" "last" "left" "level" "like" "lineno" "load" "max" "min"
1876 "mirrorexit" "national" "next" "nocheck" "nolock" "nonclustered" "not"
1877 "null" "nullif" "of" "off" "offsets" "on" "once" "only" "open"
1878 "opendatasource" "openquery" "openrowset" "option" "or" "order"
1879 "outer" "output" "over" "paglock" "percent" "perm" "permanent" "pipe"
1880 "plan" "precision" "prepare" "primary" "print" "prior" "privileges"
1881 "proc" "procedure" "processexit" "public" "raiserror" "read"
1882 "readcommitted" "readpast" "readtext" "readuncommitted" "reconfigure"
1883 "references" "relative" "repeatable" "repeatableread" "replication"
1884 "restore" "restrict" "return" "revoke" "right" "rollback" "rowcount"
1885 "rowguidcol" "rowlock" "rule" "save" "schema" "select" "serializable"
1886 "session_user" "set" "shutdown" "some" "statistics" "sum"
1887 "system_user" "table" "tablock" "tablockx" "tape" "temp" "temporary"
1888 "textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate"
1889 "tsequal" "uncommitted" "union" "unique" "update" "updatetext"
1890 "updlock" "use" "user" "values" "view" "waitfor" "when" "where"
1891 "while" "with" "work" "writetext" "collate" "function" "openxml"
1892 "returns"
1893 )
1894
1895 ;; MS Functions
1896 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1897 "@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts"
1898 "@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy"
1899 "@@langid" "@@language" "@@lock_timeout" "@@max_connections"
1900 "@@max_precision" "@@nestlevel" "@@options" "@@pack_received"
1901 "@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount"
1902 "@@servername" "@@servicename" "@@spid" "@@textsize" "@@timeticks"
1903 "@@total_errors" "@@total_read" "@@total_write" "@@trancount"
1904 "@@version" "abs" "acos" "and" "app_name" "ascii" "asin" "atan" "atn2"
1905 "avg" "case" "cast" "ceiling" "char" "charindex" "coalesce"
1906 "col_length" "col_name" "columnproperty" "containstable" "convert"
1907 "cos" "cot" "count" "current_timestamp" "current_user" "cursor_status"
1908 "databaseproperty" "datalength" "dateadd" "datediff" "datename"
1909 "datepart" "day" "db_id" "db_name" "degrees" "difference" "exp"
1910 "file_id" "file_name" "filegroup_id" "filegroup_name"
1911 "filegroupproperty" "fileproperty" "floor" "formatmessage"
1912 "freetexttable" "fulltextcatalogproperty" "fulltextserviceproperty"
1913 "getansinull" "getdate" "grouping" "host_id" "host_name" "ident_incr"
1914 "ident_seed" "identity" "index_col" "indexproperty" "is_member"
1915 "is_srvrolemember" "isdate" "isnull" "isnumeric" "left" "len" "log"
1916 "log10" "lower" "ltrim" "max" "min" "month" "nchar" "newid" "nullif"
1917 "object_id" "object_name" "objectproperty" "openquery" "openrowset"
1918 "parsename" "patindex" "patindex" "permissions" "pi" "power"
1919 "quotename" "radians" "rand" "replace" "replicate" "reverse" "right"
1920 "round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt"
1921 "square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum"
1922 "suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan"
1923 "textptr" "textvalid" "typeproperty" "unicode" "upper" "user"
1924 "user_id" "user_name" "var" "varp" "year"
1925 )
1926
1927 ;; MS Variables
1928 '("\\b@[a-zA-Z0-9_]*\\b" . font-lock-variable-name-face)
1929
1930 ;; MS Types
1931 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1932 "binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal"
1933 "double" "float" "image" "int" "integer" "money" "national" "nchar"
1934 "ntext" "numeric" "numeric" "nvarchar" "precision" "real"
1935 "smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint"
1936 "uniqueidentifier" "varbinary" "varchar" "varying"
1937 )))
1938
1939 "Microsoft SQLServer SQL keywords used by font-lock.
1940
1941 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1942 regular expressions are created during compilation by calling the
1943 function `regexp-opt'. Therefore, take a look at the source before
1944 you define your own `sql-mode-ms-font-lock-keywords'.")
1945
1946 (defvar sql-mode-sybase-font-lock-keywords nil
1947 "Sybase SQL keywords used by font-lock.
1948
1949 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1950 regular expressions are created during compilation by calling the
1951 function `regexp-opt'. Therefore, take a look at the source before
1952 you define your own `sql-mode-sybase-font-lock-keywords'.")
1953
1954 (defvar sql-mode-informix-font-lock-keywords nil
1955 "Informix SQL keywords used by font-lock.
1956
1957 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1958 regular expressions are created during compilation by calling the
1959 function `regexp-opt'. Therefore, take a look at the source before
1960 you define your own `sql-mode-informix-font-lock-keywords'.")
1961
1962 (defvar sql-mode-interbase-font-lock-keywords nil
1963 "Interbase SQL keywords used by font-lock.
1964
1965 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1966 regular expressions are created during compilation by calling the
1967 function `regexp-opt'. Therefore, take a look at the source before
1968 you define your own `sql-mode-interbase-font-lock-keywords'.")
1969
1970 (defvar sql-mode-ingres-font-lock-keywords nil
1971 "Ingres SQL keywords used by font-lock.
1972
1973 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1974 regular expressions are created during compilation by calling the
1975 function `regexp-opt'. Therefore, take a look at the source before
1976 you define your own `sql-mode-interbase-font-lock-keywords'.")
1977
1978 (defvar sql-mode-solid-font-lock-keywords nil
1979 "Solid SQL keywords used by font-lock.
1980
1981 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1982 regular expressions are created during compilation by calling the
1983 function `regexp-opt'. Therefore, take a look at the source before
1984 you define your own `sql-mode-solid-font-lock-keywords'.")
1985
1986 (defvar sql-mode-mysql-font-lock-keywords
1987 (eval-when-compile
1988 (list
1989 ;; MySQL Functions
1990 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1991 "ascii" "avg" "bdmpolyfromtext" "bdmpolyfromwkb" "bdpolyfromtext"
1992 "bdpolyfromwkb" "benchmark" "bin" "bit_and" "bit_length" "bit_or"
1993 "bit_xor" "both" "cast" "char_length" "character_length" "coalesce"
1994 "concat" "concat_ws" "connection_id" "conv" "convert" "count"
1995 "curdate" "current_date" "current_time" "current_timestamp" "curtime"
1996 "elt" "encrypt" "export_set" "field" "find_in_set" "found_rows" "from"
1997 "geomcollfromtext" "geomcollfromwkb" "geometrycollectionfromtext"
1998 "geometrycollectionfromwkb" "geometryfromtext" "geometryfromwkb"
1999 "geomfromtext" "geomfromwkb" "get_lock" "group_concat" "hex" "ifnull"
2000 "instr" "interval" "isnull" "last_insert_id" "lcase" "leading"
2001 "length" "linefromtext" "linefromwkb" "linestringfromtext"
2002 "linestringfromwkb" "load_file" "locate" "lower" "lpad" "ltrim"
2003 "make_set" "master_pos_wait" "max" "mid" "min" "mlinefromtext"
2004 "mlinefromwkb" "mpointfromtext" "mpointfromwkb" "mpolyfromtext"
2005 "mpolyfromwkb" "multilinestringfromtext" "multilinestringfromwkb"
2006 "multipointfromtext" "multipointfromwkb" "multipolygonfromtext"
2007 "multipolygonfromwkb" "now" "nullif" "oct" "octet_length" "ord"
2008 "pointfromtext" "pointfromwkb" "polyfromtext" "polyfromwkb"
2009 "polygonfromtext" "polygonfromwkb" "position" "quote" "rand"
2010 "release_lock" "repeat" "replace" "reverse" "rpad" "rtrim" "soundex"
2011 "space" "std" "stddev" "substring" "substring_index" "sum" "sysdate"
2012 "trailing" "trim" "ucase" "unix_timestamp" "upper" "user" "variance"
2013 )
2014
2015 ;; MySQL Keywords
2016 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2017 "action" "add" "after" "against" "all" "alter" "and" "as" "asc"
2018 "auto_increment" "avg_row_length" "bdb" "between" "by" "cascade"
2019 "case" "change" "character" "check" "checksum" "close" "collate"
2020 "collation" "column" "columns" "comment" "committed" "concurrent"
2021 "constraint" "create" "cross" "data" "database" "default"
2022 "delay_key_write" "delayed" "delete" "desc" "directory" "disable"
2023 "distinct" "distinctrow" "do" "drop" "dumpfile" "duplicate" "else"
2024 "enable" "enclosed" "end" "escaped" "exists" "fields" "first" "for"
2025 "force" "foreign" "from" "full" "fulltext" "global" "group" "handler"
2026 "having" "heap" "high_priority" "if" "ignore" "in" "index" "infile"
2027 "inner" "insert" "insert_method" "into" "is" "isam" "isolation" "join"
2028 "key" "keys" "last" "left" "level" "like" "limit" "lines" "load"
2029 "local" "lock" "low_priority" "match" "max_rows" "merge" "min_rows"
2030 "mode" "modify" "mrg_myisam" "myisam" "natural" "next" "no" "not"
2031 "null" "offset" "oj" "on" "open" "optionally" "or" "order" "outer"
2032 "outfile" "pack_keys" "partial" "password" "prev" "primary"
2033 "procedure" "quick" "raid0" "raid_type" "read" "references" "rename"
2034 "repeatable" "restrict" "right" "rollback" "rollup" "row_format"
2035 "savepoint" "select" "separator" "serializable" "session" "set"
2036 "share" "show" "sql_big_result" "sql_buffer_result" "sql_cache"
2037 "sql_calc_found_rows" "sql_no_cache" "sql_small_result" "starting"
2038 "straight_join" "striped" "table" "tables" "temporary" "terminated"
2039 "then" "to" "transaction" "truncate" "type" "uncommitted" "union"
2040 "unique" "unlock" "update" "use" "using" "values" "when" "where"
2041 "with" "write" "xor"
2042 )
2043
2044 ;; MySQL Data Types
2045 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2046 "bigint" "binary" "bit" "blob" "bool" "boolean" "char" "curve" "date"
2047 "datetime" "dec" "decimal" "double" "enum" "fixed" "float" "geometry"
2048 "geometrycollection" "int" "integer" "line" "linearring" "linestring"
2049 "longblob" "longtext" "mediumblob" "mediumint" "mediumtext"
2050 "multicurve" "multilinestring" "multipoint" "multipolygon"
2051 "multisurface" "national" "numeric" "point" "polygon" "precision"
2052 "real" "smallint" "surface" "text" "time" "timestamp" "tinyblob"
2053 "tinyint" "tinytext" "unsigned" "varchar" "year" "year2" "year4"
2054 "zerofill"
2055 )))
2056
2057 "MySQL SQL keywords used by font-lock.
2058
2059 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2060 regular expressions are created during compilation by calling the
2061 function `regexp-opt'. Therefore, take a look at the source before
2062 you define your own `sql-mode-mysql-font-lock-keywords'.")
2063
2064 (defvar sql-mode-sqlite-font-lock-keywords
2065 (eval-when-compile
2066 (list
2067 ;; SQLite commands
2068 '("^[.].*$" . font-lock-doc-face)
2069
2070 ;; SQLite Keyword
2071 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2072 "abort" "action" "add" "after" "all" "alter" "analyze" "and" "as"
2073 "asc" "attach" "autoincrement" "before" "begin" "between" "by"
2074 "cascade" "case" "cast" "check" "collate" "column" "commit" "conflict"
2075 "constraint" "create" "cross" "database" "default" "deferrable"
2076 "deferred" "delete" "desc" "detach" "distinct" "drop" "each" "else"
2077 "end" "escape" "except" "exclusive" "exists" "explain" "fail" "for"
2078 "foreign" "from" "full" "glob" "group" "having" "if" "ignore"
2079 "immediate" "in" "index" "indexed" "initially" "inner" "insert"
2080 "instead" "intersect" "into" "is" "isnull" "join" "key" "left" "like"
2081 "limit" "match" "natural" "no" "not" "notnull" "null" "of" "offset"
2082 "on" "or" "order" "outer" "plan" "pragma" "primary" "query" "raise"
2083 "references" "regexp" "reindex" "release" "rename" "replace"
2084 "restrict" "right" "rollback" "row" "savepoint" "select" "set" "table"
2085 "temp" "temporary" "then" "to" "transaction" "trigger" "union"
2086 "unique" "update" "using" "vacuum" "values" "view" "virtual" "when"
2087 "where"
2088 )
2089 ;; SQLite Data types
2090 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2091 "int" "integer" "tinyint" "smallint" "mediumint" "bigint" "unsigned"
2092 "big" "int2" "int8" "character" "varchar" "varying" "nchar" "native"
2093 "nvarchar" "text" "clob" "blob" "real" "double" "precision" "float"
2094 "numeric" "number" "decimal" "boolean" "date" "datetime"
2095 )
2096 ;; SQLite Functions
2097 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
2098 ;; Core functions
2099 "abs" "changes" "coalesce" "glob" "ifnull" "hex" "last_insert_rowid"
2100 "length" "like" "load_extension" "lower" "ltrim" "max" "min" "nullif"
2101 "quote" "random" "randomblob" "replace" "round" "rtrim" "soundex"
2102 "sqlite_compileoption_get" "sqlite_compileoption_used"
2103 "sqlite_source_id" "sqlite_version" "substr" "total_changes" "trim"
2104 "typeof" "upper" "zeroblob"
2105 ;; Date/time functions
2106 "time" "julianday" "strftime"
2107 "current_date" "current_time" "current_timestamp"
2108 ;; Aggregate functions
2109 "avg" "count" "group_concat" "max" "min" "sum" "total"
2110 )))
2111
2112 "SQLite SQL keywords used by font-lock.
2113
2114 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2115 regular expressions are created during compilation by calling the
2116 function `regexp-opt'. Therefore, take a look at the source before
2117 you define your own `sql-mode-sqlite-font-lock-keywords'.")
2118
2119 (defvar sql-mode-db2-font-lock-keywords nil
2120 "DB2 SQL keywords used by font-lock.
2121
2122 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2123 regular expressions are created during compilation by calling the
2124 function `regexp-opt'. Therefore, take a look at the source before
2125 you define your own `sql-mode-db2-font-lock-keywords'.")
2126
2127 (defvar sql-mode-font-lock-keywords nil
2128 "SQL keywords used by font-lock.
2129
2130 Setting this variable directly no longer has any affect. Use
2131 `sql-product' and `sql-add-product-keywords' to control the
2132 highlighting rules in SQL mode.")
2133
2134 \f
2135
2136 ;;; SQL Product support functions
2137
2138 (defun sql-add-product (product display &rest plist)
2139 "Add support for a database product in `sql-mode'.
2140
2141 Add PRODUCT to `sql-product-alist' which enables `sql-mode' to
2142 properly support syntax highlighting and interactive interaction.
2143 DISPLAY is the name of the SQL product that will appear in the
2144 menu bar and in messages. PLIST initializes the product
2145 configuration."
2146
2147 ;; Don't do anything if the product is already supported
2148 (if (assoc product sql-product-alist)
2149 (message "Product `%s' is already defined" product)
2150
2151 ;; Add product to the alist
2152 (add-to-list 'sql-product-alist `((,product :name ,display . ,plist)))
2153 ;; Add a menu item to the SQL->Product menu
2154 (easy-menu-add-item sql-mode-menu '("Product")
2155 ;; Each product is represented by a radio
2156 ;; button with it's display name.
2157 `[,display
2158 (sql-set-product ',product)
2159 :style radio
2160 :selected (eq sql-product ',product)]
2161 ;; Maintain the product list in
2162 ;; (case-insensitive) alphabetic order of the
2163 ;; display names. Loop thru each keymap item
2164 ;; looking for an item whose display name is
2165 ;; after this product's name.
2166 (let ((next-item)
2167 (down-display (downcase display)))
2168 (map-keymap (lambda (k b)
2169 (when (and (not next-item)
2170 (string-lessp down-display
2171 (downcase (cadr b))))
2172 (setq next-item k)))
2173 (easy-menu-get-map sql-mode-menu '("Product")))
2174 next-item))
2175 product))
2176
2177 (defun sql-del-product (product)
2178 "Remove support for PRODUCT in `sql-mode'."
2179
2180 ;; Remove the menu item based on the display name
2181 (easy-menu-remove-item sql-mode-menu '("Product") (sql-get-product-feature product :name))
2182 ;; Remove the product alist item
2183 (setq sql-product-alist (assq-delete-all product sql-product-alist))
2184 nil)
2185
2186 (defun sql-set-product-feature (product feature newvalue)
2187 "Set FEATURE of database PRODUCT to NEWVALUE.
2188
2189 The PRODUCT must be a symbol which identifies the database
2190 product. The product must have already exist on the product
2191 list. See `sql-add-product' to add new products. The FEATURE
2192 argument must be a plist keyword accepted by
2193 `sql-product-alist'."
2194
2195 (let* ((p (assoc product sql-product-alist))
2196 (v (plist-get (cdr p) feature)))
2197 (if p
2198 (if (and
2199 (member feature sql-indirect-features)
2200 (symbolp v))
2201 (set v newvalue)
2202 (setcdr p (plist-put (cdr p) feature newvalue)))
2203 (message "`%s' is not a known product; use `sql-add-product' to add it first." product))))
2204
2205 (defun sql-get-product-feature (product feature &optional fallback not-indirect)
2206 "Lookup FEATURE associated with a SQL PRODUCT.
2207
2208 If the FEATURE is nil for PRODUCT, and FALLBACK is specified,
2209 then the FEATURE associated with the FALLBACK product is
2210 returned.
2211
2212 If the FEATURE is in the list `sql-indirect-features', and the
2213 NOT-INDIRECT parameter is not set, then the value of the symbol
2214 stored in the connect alist is returned.
2215
2216 See `sql-product-alist' for a list of products and supported features."
2217 (let* ((p (assoc product sql-product-alist))
2218 (v (plist-get (cdr p) feature)))
2219
2220 (if p
2221 ;; If no value and fallback, lookup feature for fallback
2222 (if (and (not v)
2223 fallback
2224 (not (eq product fallback)))
2225 (sql-get-product-feature fallback feature)
2226
2227 (if (and
2228 (member feature sql-indirect-features)
2229 (not not-indirect)
2230 (symbolp v))
2231 (symbol-value v)
2232 v))
2233 (message "`%s' is not a known product; use `sql-add-product' to add it first." product)
2234 nil)))
2235
2236 (defun sql-product-font-lock (keywords-only imenu)
2237 "Configure font-lock and imenu with product-specific settings.
2238
2239 The KEYWORDS-ONLY flag is passed to font-lock to specify whether
2240 only keywords should be hilighted and syntactic hilighting
2241 skipped. The IMENU flag indicates whether `imenu-mode' should
2242 also be configured."
2243
2244 (let
2245 ;; Get the product-specific syntax-alist.
2246 ((syntax-alist
2247 (append
2248 (sql-get-product-feature sql-product :syntax-alist)
2249 '((?_ . "w") (?. . "w")))))
2250
2251 ;; Get the product-specific keywords.
2252 (setq sql-mode-font-lock-keywords
2253 (append
2254 (unless (eq sql-product 'ansi)
2255 (sql-get-product-feature sql-product :font-lock))
2256 ;; Always highlight ANSI keywords
2257 (sql-get-product-feature 'ansi :font-lock)
2258 ;; Fontify object names in CREATE, DROP and ALTER DDL
2259 ;; statements
2260 (list sql-mode-font-lock-object-name)))
2261
2262 ;; Setup font-lock. Force re-parsing of `font-lock-defaults'.
2263 (kill-local-variable 'font-lock-set-defaults)
2264 (setq font-lock-defaults (list 'sql-mode-font-lock-keywords
2265 keywords-only t syntax-alist))
2266
2267 ;; Force font lock to reinitialize if it is already on
2268 ;; Otherwise, we can wait until it can be started.
2269 (when (and (fboundp 'font-lock-mode)
2270 (boundp 'font-lock-mode)
2271 font-lock-mode)
2272 (font-lock-mode-internal nil)
2273 (font-lock-mode-internal t))
2274
2275 (add-hook 'font-lock-mode-hook
2276 (lambda ()
2277 ;; Provide defaults for new font-lock faces.
2278 (defvar font-lock-builtin-face
2279 (if (boundp 'font-lock-preprocessor-face)
2280 font-lock-preprocessor-face
2281 font-lock-keyword-face))
2282 (defvar font-lock-doc-face font-lock-string-face))
2283 nil t)
2284
2285 ;; Setup imenu; it needs the same syntax-alist.
2286 (when imenu
2287 (setq imenu-syntax-alist syntax-alist))))
2288
2289 ;;;###autoload
2290 (defun sql-add-product-keywords (product keywords &optional append)
2291 "Add highlighting KEYWORDS for SQL PRODUCT.
2292
2293 PRODUCT should be a symbol, the name of a SQL product, such as
2294 `oracle'. KEYWORDS should be a list; see the variable
2295 `font-lock-keywords'. By default they are added at the beginning
2296 of the current highlighting list. If optional argument APPEND is
2297 `set', they are used to replace the current highlighting list.
2298 If APPEND is any other non-nil value, they are added at the end
2299 of the current highlighting list.
2300
2301 For example:
2302
2303 (sql-add-product-keywords 'ms
2304 '((\"\\\\b\\\\w+_t\\\\b\" . font-lock-type-face)))
2305
2306 adds a fontification pattern to fontify identifiers ending in
2307 `_t' as data types."
2308
2309 (let* ((sql-indirect-features nil)
2310 (font-lock-var (sql-get-product-feature product :font-lock))
2311 (old-val))
2312
2313 (setq old-val (symbol-value font-lock-var))
2314 (set font-lock-var
2315 (if (eq append 'set)
2316 keywords
2317 (if append
2318 (append old-val keywords)
2319 (append keywords old-val))))))
2320
2321 (defun sql-for-each-login (login-params body)
2322 "Iterates through login parameters and returns a list of results."
2323
2324 (delq nil
2325 (mapcar
2326 (lambda (param)
2327 (let ((token (or (and (listp param) (car param)) param))
2328 (type (or (and (listp param) (nth 1 param)) nil))
2329 (arg (or (and (listp param) (nth 2 param)) nil)))
2330
2331 (funcall body token type arg)))
2332 login-params)))
2333
2334 \f
2335
2336 ;;; Functions to switch highlighting
2337
2338 (defun sql-highlight-product ()
2339 "Turn on the font highlighting for the SQL product selected."
2340 (when (derived-mode-p 'sql-mode)
2341 ;; Setup font-lock
2342 (sql-product-font-lock nil t)
2343
2344 ;; Set the mode name to include the product.
2345 (setq mode-name (concat "SQL[" (or (sql-get-product-feature sql-product :name)
2346 (symbol-name sql-product)) "]"))))
2347
2348 (defun sql-set-product (product)
2349 "Set `sql-product' to PRODUCT and enable appropriate highlighting."
2350 (interactive
2351 (list (completing-read "SQL product: "
2352 (mapcar (lambda (info) (symbol-name (car info)))
2353 sql-product-alist)
2354 nil 'require-match
2355 (or (and sql-product (symbol-name sql-product)) "ansi"))))
2356 (if (stringp product) (setq product (intern product)))
2357 (when (not (assoc product sql-product-alist))
2358 (error "SQL product %s is not supported; treated as ANSI" product)
2359 (setq product 'ansi))
2360
2361 ;; Save product setting and fontify.
2362 (setq sql-product product)
2363 (sql-highlight-product))
2364 \f
2365
2366 ;;; Compatibility functions
2367
2368 (if (not (fboundp 'comint-line-beginning-position))
2369 ;; comint-line-beginning-position is defined in Emacs 21
2370 (defun comint-line-beginning-position ()
2371 "Return the buffer position of the beginning of the line, after any prompt.
2372 The prompt is assumed to be any text at the beginning of the line matching
2373 the regular expression `comint-prompt-regexp', a buffer local variable."
2374 (save-excursion (comint-bol nil) (point))))
2375
2376 \f
2377
2378 ;;; Small functions
2379
2380 (defun sql-magic-go (arg)
2381 "Insert \"o\" and call `comint-send-input'.
2382 `sql-electric-stuff' must be the symbol `go'."
2383 (interactive "P")
2384 (self-insert-command (prefix-numeric-value arg))
2385 (if (and (equal sql-electric-stuff 'go)
2386 (save-excursion
2387 (comint-bol nil)
2388 (looking-at "go\\b")))
2389 (comint-send-input)))
2390
2391 (defun sql-magic-semicolon (arg)
2392 "Insert semicolon and call `comint-send-input'.
2393 `sql-electric-stuff' must be the symbol `semicolon'."
2394 (interactive "P")
2395 (self-insert-command (prefix-numeric-value arg))
2396 (if (equal sql-electric-stuff 'semicolon)
2397 (comint-send-input)))
2398
2399 (defun sql-accumulate-and-indent ()
2400 "Continue SQL statement on the next line."
2401 (interactive)
2402 (if (fboundp 'comint-accumulate)
2403 (comint-accumulate)
2404 (newline))
2405 (indent-according-to-mode))
2406
2407 (defun sql-help-list-products (indent freep)
2408 "Generate listing of products available for use under SQLi.
2409
2410 List products with :free-softare attribute set to FREEP. Indent
2411 each line with INDENT."
2412
2413 (let (sqli-func doc)
2414 (setq doc "")
2415 (dolist (p sql-product-alist)
2416 (setq sqli-func (intern (concat "sql-" (symbol-name (car p)))))
2417
2418 (if (and (fboundp sqli-func)
2419 (eq (sql-get-product-feature (car p) :free-software) freep))
2420 (setq doc
2421 (concat doc
2422 indent
2423 (or (sql-get-product-feature (car p) :name)
2424 (symbol-name (car p)))
2425 ":\t"
2426 "\\["
2427 (symbol-name sqli-func)
2428 "]\n"))))
2429 doc))
2430
2431 ;;;###autoload
2432 (defun sql-help ()
2433 "Show short help for the SQL modes.
2434
2435 Use an entry function to open an interactive SQL buffer. This buffer is
2436 usually named `*SQL*'. The name of the major mode is SQLi.
2437
2438 Use the following commands to start a specific SQL interpreter:
2439
2440 \\\\FREE
2441
2442 Other non-free SQL implementations are also supported:
2443
2444 \\\\NONFREE
2445
2446 But we urge you to choose a free implementation instead of these.
2447
2448 You can also use \\[sql-product-interactive] to invoke the
2449 interpreter for the current `sql-product'.
2450
2451 Once you have the SQLi buffer, you can enter SQL statements in the
2452 buffer. The output generated is appended to the buffer and a new prompt
2453 is generated. See the In/Out menu in the SQLi buffer for some functions
2454 that help you navigate through the buffer, the input history, etc.
2455
2456 If you have a really complex SQL statement or if you are writing a
2457 procedure, you can do this in a separate buffer. Put the new buffer in
2458 `sql-mode' by calling \\[sql-mode]. The name of this buffer can be
2459 anything. The name of the major mode is SQL.
2460
2461 In this SQL buffer (SQL mode), you can send the region or the entire
2462 buffer to the interactive SQL buffer (SQLi mode). The results are
2463 appended to the SQLi buffer without disturbing your SQL buffer."
2464 (interactive)
2465
2466 ;; Insert references to loaded products into the help buffer string
2467 (let ((doc (documentation 'sql-help t))
2468 changedp)
2469 (setq changedp nil)
2470
2471 ;; Insert FREE software list
2472 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]FREE\\s-*\n" doc 0)
2473 (setq doc (replace-match (sql-help-list-products (match-string 1 doc) t)
2474 t t doc 0)
2475 changedp t))
2476
2477 ;; Insert non-FREE software list
2478 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]NONFREE\\s-*\n" doc 0)
2479 (setq doc (replace-match (sql-help-list-products (match-string 1 doc) nil)
2480 t t doc 0)
2481 changedp t))
2482
2483 ;; If we changed the help text, save the change so that the help
2484 ;; sub-system will see it
2485 (when changedp
2486 (put 'sql-help 'function-documentation doc)))
2487
2488 ;; Call help on this function
2489 (describe-function 'sql-help))
2490
2491 (defun sql-read-passwd (prompt &optional default)
2492 "Read a password using PROMPT. Optional DEFAULT is password to start with."
2493 (read-passwd prompt nil default))
2494
2495 (defun sql-get-login-ext (prompt last-value history-var type arg)
2496 "Prompt user with extended login parameters.
2497
2498 If TYPE is nil, then the user is simply prompted for a string
2499 value.
2500
2501 If TYPE is `:file', then the user is prompted for a file
2502 name that must match the regexp pattern specified in the ARG
2503 argument.
2504
2505 If TYPE is `:completion', then the user is prompted for a string
2506 specified by ARG. (ARG is used as the PREDICATE argument to
2507 `completing-read'.)"
2508 (cond
2509 ((eq type nil)
2510 (read-from-minibuffer prompt last-value nil nil history-var))
2511
2512 ((eq type :file)
2513 (let ((use-dialog-box nil))
2514 (expand-file-name
2515 (read-file-name prompt
2516 (file-name-directory last-value) nil t
2517 (file-name-nondirectory last-value)
2518 (if arg
2519 `(lambda (f)
2520 (string-match (concat "\\<" ,arg "\\>")
2521 (file-name-nondirectory f)))
2522 nil)))))
2523
2524 ((eq type :completion)
2525 (completing-read prompt arg nil t last-value history-var))))
2526
2527 (defun sql-get-login (&rest what)
2528 "Get username, password and database from the user.
2529
2530 The variables `sql-user', `sql-password', `sql-server', and
2531 `sql-database' can be customized. They are used as the default values.
2532 Usernames, servers and databases are stored in `sql-user-history',
2533 `sql-server-history' and `database-history'. Passwords are not stored
2534 in a history.
2535
2536 Parameter WHAT is a list of tokens passed as arguments in the
2537 function call. The function asks for the username if WHAT
2538 contains the symbol `user', for the password if it contains the
2539 symbol `password', for the server if it contains the symbol
2540 `server', and for the database if it contains the symbol
2541 `database'. The members of WHAT are processed in the order in
2542 which they are provided.
2543
2544 The tokens for `database' and `server' may also be lists to
2545 control or limit the values that can be supplied. These can be
2546 of the form:
2547
2548 \(database :file \".+\\\\.EXT\")
2549 \(database :completion FUNCTION)
2550
2551 The `server' token supports the same forms.
2552
2553 In order to ask the user for username, password and database, call the
2554 function like this: (sql-get-login 'user 'password 'database)."
2555 (interactive)
2556 (mapcar
2557 (lambda (w)
2558 (let ((token (or (and (listp w) (car w)) w))
2559 (type (or (and (listp w) (nth 1 w)) nil))
2560 (arg (or (and (listp w) (nth 2 w)) nil)))
2561
2562 (cond
2563 ((eq token 'user) ; user
2564 (setq sql-user
2565 (read-from-minibuffer "User: " sql-user nil nil
2566 'sql-user-history)))
2567
2568 ((eq token 'password) ; password
2569 (setq sql-password
2570 (sql-read-passwd "Password: " sql-password)))
2571
2572 ((eq token 'server) ; server
2573 (setq sql-server
2574 (sql-get-login-ext "Server: " sql-server
2575 'sql-server-history type arg)))
2576
2577 ((eq token 'database) ; database
2578 (setq sql-database
2579 (sql-get-login-ext "Database: " sql-database
2580 'sql-database-history type arg)))
2581
2582 ((eq token 'port) ; port
2583 (setq sql-port
2584 (read-number "Port: " (if (numberp sql-port)
2585 sql-port
2586 0)))))))
2587 what))
2588
2589 (defun sql-find-sqli-buffer ()
2590 "Returns the name of the current default SQLi buffer or nil.
2591 In order to qualify, the SQLi buffer must be alive, be in
2592 `sql-interactive-mode' and have a process."
2593 (let ((buf sql-buffer)
2594 (prod sql-product))
2595 (or
2596 ;; Current sql-buffer, if there is one.
2597 (and (sql-buffer-live-p buf prod)
2598 buf)
2599 ;; Global sql-buffer
2600 (and (setq buf (default-value 'sql-buffer))
2601 (sql-buffer-live-p buf prod)
2602 buf)
2603 ;; Look thru each buffer
2604 (car (apply 'append
2605 (mapcar (lambda (b)
2606 (and (sql-buffer-live-p b prod)
2607 (list (buffer-name b))))
2608 (buffer-list)))))))
2609
2610 (defun sql-set-sqli-buffer-generally ()
2611 "Set SQLi buffer for all SQL buffers that have none.
2612 This function checks all SQL buffers for their SQLi buffer. If their
2613 SQLi buffer is nonexistent or has no process, it is set to the current
2614 default SQLi buffer. The current default SQLi buffer is determined
2615 using `sql-find-sqli-buffer'. If `sql-buffer' is set,
2616 `sql-set-sqli-hook' is run."
2617 (interactive)
2618 (save-excursion
2619 (let ((buflist (buffer-list))
2620 (default-buffer (sql-find-sqli-buffer)))
2621 (setq-default sql-buffer default-buffer)
2622 (while (not (null buflist))
2623 (let ((candidate (car buflist)))
2624 (set-buffer candidate)
2625 (if (and (derived-mode-p 'sql-mode)
2626 (not (sql-buffer-live-p sql-buffer)))
2627 (progn
2628 (setq sql-buffer default-buffer)
2629 (when default-buffer
2630 (run-hooks 'sql-set-sqli-hook)))))
2631 (setq buflist (cdr buflist))))))
2632
2633 (defun sql-set-sqli-buffer ()
2634 "Set the SQLi buffer SQL strings are sent to.
2635
2636 Call this function in a SQL buffer in order to set the SQLi buffer SQL
2637 strings are sent to. Calling this function sets `sql-buffer' and runs
2638 `sql-set-sqli-hook'.
2639
2640 If you call it from a SQL buffer, this sets the local copy of
2641 `sql-buffer'.
2642
2643 If you call it from anywhere else, it sets the global copy of
2644 `sql-buffer'."
2645 (interactive)
2646 (let ((default-buffer (sql-find-sqli-buffer)))
2647 (if (null default-buffer)
2648 (error "There is no suitable SQLi buffer")
2649 (let ((new-buffer (read-buffer "New SQLi buffer: " default-buffer t)))
2650 (if (null (sql-buffer-live-p new-buffer))
2651 (error "Buffer %s is not a working SQLi buffer" new-buffer)
2652 (when new-buffer
2653 (setq sql-buffer new-buffer)
2654 (run-hooks 'sql-set-sqli-hook)))))))
2655
2656 (defun sql-show-sqli-buffer ()
2657 "Show the name of current SQLi buffer.
2658
2659 This is the buffer SQL strings are sent to. It is stored in the
2660 variable `sql-buffer'. See `sql-help' on how to create such a buffer."
2661 (interactive)
2662 (if (null (buffer-live-p (get-buffer sql-buffer)))
2663 (message "%s has no SQLi buffer set." (buffer-name (current-buffer)))
2664 (if (null (get-buffer-process sql-buffer))
2665 (message "Buffer %s has no process." sql-buffer)
2666 (message "Current SQLi buffer is %s." sql-buffer))))
2667
2668 (defun sql-make-alternate-buffer-name ()
2669 "Return a string that can be used to rename a SQLi buffer.
2670
2671 This is used to set `sql-alternate-buffer-name' within
2672 `sql-interactive-mode'.
2673
2674 If the session was started with `sql-connect' then the alternate
2675 name would be the name of the connection.
2676
2677 Otherwise, it uses the parameters identified by the :sqlilogin
2678 parameter.
2679
2680 If all else fails, the alternate name would be the user and
2681 server/database name."
2682
2683 (let ((name ""))
2684
2685 ;; Build a name using the :sqli-login setting
2686 (setq name
2687 (apply 'concat
2688 (cdr
2689 (apply 'append nil
2690 (sql-for-each-login
2691 (sql-get-product-feature sql-product :sqli-login)
2692 (lambda (token type arg)
2693 (cond
2694 ((eq token 'user)
2695 (unless (string= "" sql-user)
2696 (list "/" sql-user)))
2697 ((eq token 'port)
2698 (unless (or (not (numberp sql-port))
2699 (= 0 sql-port))
2700 (list ":" (number-to-string sql-port))))
2701 ((eq token 'server)
2702 (unless (string= "" sql-server)
2703 (list "."
2704 (if (eq type :file)
2705 (file-name-nondirectory sql-server)
2706 sql-server))))
2707 ((eq token 'database)
2708 (unless (string= "" sql-database)
2709 (list "@"
2710 (if (eq type :file)
2711 (file-name-nondirectory sql-database)
2712 sql-database))))
2713
2714 ((eq token 'password) nil)
2715 (t nil))))))))
2716
2717 ;; If there's a connection, use it and the name thus far
2718 (if sql-connection
2719 (format "<%s>%s" sql-connection (or name ""))
2720
2721 ;; If there is no name, try to create something meaningful
2722 (if (string= "" (or name ""))
2723 (concat
2724 (if (string= "" sql-user)
2725 (if (string= "" (user-login-name))
2726 ()
2727 (concat (user-login-name) "/"))
2728 (concat sql-user "/"))
2729 (if (string= "" sql-database)
2730 (if (string= "" sql-server)
2731 (system-name)
2732 sql-server)
2733 sql-database))
2734
2735 ;; Use the name we've got
2736 name))))
2737
2738 (defun sql-rename-buffer (&optional new-name)
2739 "Rename a SQL interactive buffer.
2740
2741 Prompts for the new name if command is preceeded by
2742 \\[universal-argument]. If no buffer name is provided, then the
2743 `sql-alternate-buffer-name' is used.
2744
2745 The actual buffer name set will be \"*SQL: NEW-NAME*\". If
2746 NEW-NAME is empty, then the buffer name will be \"*SQL*\"."
2747 (interactive "P")
2748
2749 (if (not (derived-mode-p 'sql-interactive-mode))
2750 (message "Current buffer is not a SQL interactive buffer")
2751
2752 (setq sql-alternate-buffer-name
2753 (cond
2754 ((stringp new-name) new-name)
2755 ((consp new-name)
2756 (read-string "Buffer name (\"*SQL: XXX*\"; enter `XXX'): "
2757 sql-alternate-buffer-name))
2758 (t sql-alternate-buffer-name)))
2759
2760 (rename-buffer (if (string= "" sql-alternate-buffer-name)
2761 "*SQL*"
2762 (format "*SQL: %s*" sql-alternate-buffer-name))
2763 t)))
2764
2765 (defun sql-copy-column ()
2766 "Copy current column to the end of buffer.
2767 Inserts SELECT or commas if appropriate."
2768 (interactive)
2769 (let ((column))
2770 (save-excursion
2771 (setq column (buffer-substring-no-properties
2772 (progn (forward-char 1) (backward-sexp 1) (point))
2773 (progn (forward-sexp 1) (point))))
2774 (goto-char (point-max))
2775 (let ((bol (comint-line-beginning-position)))
2776 (cond
2777 ;; if empty command line, insert SELECT
2778 ((= bol (point))
2779 (insert "SELECT "))
2780 ;; else if appending to INTO .* (, SELECT or ORDER BY, insert a comma
2781 ((save-excursion
2782 (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+"
2783 bol t))
2784 (insert ", "))
2785 ;; else insert a space
2786 (t
2787 (if (eq (preceding-char) ?\s)
2788 nil
2789 (insert " ")))))
2790 ;; in any case, insert the column
2791 (insert column)
2792 (message "%s" column))))
2793
2794 ;; On Windows, SQL*Plus for Oracle turns on full buffering for stdout
2795 ;; if it is not attached to a character device; therefore placeholder
2796 ;; replacement by SQL*Plus is fully buffered. The workaround lets
2797 ;; Emacs query for the placeholders.
2798
2799 (defvar sql-placeholder-history nil
2800 "History of placeholder values used.")
2801
2802 (defun sql-placeholders-filter (string)
2803 "Replace placeholders in STRING.
2804 Placeholders are words starting with an ampersand like &this."
2805
2806 (when sql-oracle-scan-on
2807 (while (string-match "&\\(\\sw+\\)" string)
2808 (setq string (replace-match
2809 (read-from-minibuffer
2810 (format "Enter value for %s: " (match-string 1 string))
2811 nil nil nil 'sql-placeholder-history)
2812 t t string))))
2813 string)
2814
2815 ;; Using DB2 interactively, newlines must be escaped with " \".
2816 ;; The space before the backslash is relevant.
2817 (defun sql-escape-newlines-filter (string)
2818 "Escape newlines in STRING.
2819 Every newline in STRING will be preceded with a space and a backslash."
2820 (let ((result "") (start 0) mb me)
2821 (while (string-match "\n" string start)
2822 (setq mb (match-beginning 0)
2823 me (match-end 0)
2824 result (concat result
2825 (substring string start mb)
2826 (if (and (> mb 1)
2827 (string-equal " \\" (substring string (- mb 2) mb)))
2828 "" " \\\n"))
2829 start me))
2830 (concat result (substring string start))))
2831
2832 \f
2833
2834 ;;; Input sender for SQLi buffers
2835
2836 (defvar sql-output-newline-count 0
2837 "Number of newlines in the input string.
2838
2839 Allows the suppression of continuation prompts.")
2840
2841 (defvar sql-output-by-send nil
2842 "Non-nil if the command in the input was generated by `sql-send-string'.")
2843
2844 (defun sql-input-sender (proc string)
2845 "Send STRING to PROC after applying filters."
2846
2847 (let* ((product (with-current-buffer (process-buffer proc) sql-product))
2848 (filter (sql-get-product-feature product :input-filter)))
2849
2850 ;; Apply filter(s)
2851 (cond
2852 ((not filter)
2853 nil)
2854 ((functionp filter)
2855 (setq string (funcall filter string)))
2856 ((listp filter)
2857 (mapc (lambda (f) (setq string (funcall f string))) filter))
2858 (t nil))
2859
2860 ;; Count how many newlines in the string
2861 (setq sql-output-newline-count 0)
2862 (mapc (lambda (ch)
2863 (when (eq ch ?\n)
2864 (setq sql-output-newline-count (1+ sql-output-newline-count))))
2865 string)
2866
2867 ;; Send the string
2868 (comint-simple-send proc string)))
2869
2870 ;;; Strip out continuation prompts
2871
2872 (defun sql-interactive-remove-continuation-prompt (oline)
2873 "Strip out continuation prompts out of the OLINE.
2874
2875 Added to the `comint-preoutput-filter-functions' hook in a SQL
2876 interactive buffer. If `sql-outut-newline-count' is greater than
2877 zero, then an output line matching the continuation prompt is filtered
2878 out. If the count is one, then the prompt is replaced with a newline
2879 to force the output from the query to appear on a new line."
2880 (if (and sql-prompt-cont-regexp
2881 sql-output-newline-count
2882 (numberp sql-output-newline-count)
2883 (>= sql-output-newline-count 1))
2884 (progn
2885 (while (and oline
2886 sql-output-newline-count
2887 (> sql-output-newline-count 0)
2888 (string-match sql-prompt-cont-regexp oline))
2889
2890 (setq oline
2891 (replace-match (if (and
2892 (= 1 sql-output-newline-count)
2893 sql-output-by-send)
2894 "\n" "")
2895 nil nil oline)
2896 sql-output-newline-count
2897 (1- sql-output-newline-count)))
2898 (if (= sql-output-newline-count 0)
2899 (setq sql-output-newline-count nil))
2900 (setq sql-output-by-send nil))
2901 (setq sql-output-newline-count nil))
2902 oline)
2903
2904 ;;; Sending the region to the SQLi buffer.
2905
2906 (defun sql-send-string (str)
2907 "Send the string STR to the SQL process."
2908 (interactive "sSQL Text: ")
2909
2910 (let ((comint-input-sender-no-newline nil)
2911 (s (replace-regexp-in-string "[[:space:]\n\r]+\\'" "" str)))
2912 (if (sql-buffer-live-p sql-buffer)
2913 (progn
2914 ;; Ignore the hoping around...
2915 (save-excursion
2916 ;; Set product context
2917 (with-current-buffer sql-buffer
2918 ;; Send the string (trim the trailing whitespace)
2919 (sql-input-sender (get-buffer-process sql-buffer) s)
2920
2921 ;; Send a command terminator if we must
2922 (if sql-send-terminator
2923 (sql-send-magic-terminator sql-buffer s sql-send-terminator))
2924
2925 (message "Sent string to buffer %s." sql-buffer)))
2926
2927 ;; Display the sql buffer
2928 (if sql-pop-to-buffer-after-send-region
2929 (pop-to-buffer sql-buffer)
2930 (display-buffer sql-buffer)))
2931
2932 ;; We don't have no stinkin' sql
2933 (message "No SQL process started."))))
2934
2935 (defun sql-send-region (start end)
2936 "Send a region to the SQL process."
2937 (interactive "r")
2938 (sql-send-string (buffer-substring-no-properties start end)))
2939
2940 (defun sql-send-paragraph ()
2941 "Send the current paragraph to the SQL process."
2942 (interactive)
2943 (let ((start (save-excursion
2944 (backward-paragraph)
2945 (point)))
2946 (end (save-excursion
2947 (forward-paragraph)
2948 (point))))
2949 (sql-send-region start end)))
2950
2951 (defun sql-send-buffer ()
2952 "Send the buffer contents to the SQL process."
2953 (interactive)
2954 (sql-send-region (point-min) (point-max)))
2955
2956 (defun sql-send-magic-terminator (buf str terminator)
2957 "Send TERMINATOR to buffer BUF if its not present in STR."
2958 (let (comint-input-sender-no-newline pat term)
2959 ;; If flag is merely on(t), get product-specific terminator
2960 (if (eq terminator t)
2961 (setq terminator (sql-get-product-feature sql-product :terminator)))
2962
2963 ;; If there is no terminator specified, use default ";"
2964 (unless terminator
2965 (setq terminator ";"))
2966
2967 ;; Parse the setting into the pattern and the terminator string
2968 (cond ((stringp terminator)
2969 (setq pat (regexp-quote terminator)
2970 term terminator))
2971 ((consp terminator)
2972 (setq pat (car terminator)
2973 term (cdr terminator)))
2974 (t
2975 nil))
2976
2977 ;; Check to see if the pattern is present in the str already sent
2978 (unless (and pat term
2979 (string-match (concat pat "\\'") str))
2980 (comint-simple-send (get-buffer-process buf) term)
2981 (setq sql-output-newline-count
2982 (if sql-output-newline-count
2983 (1+ sql-output-newline-count)
2984 1)))
2985 (setq sql-output-by-send t)))
2986
2987 (defun sql-remove-tabs-filter (str)
2988 "Replace tab characters with spaces."
2989 (replace-regexp-in-string "\t" " " str nil t))
2990
2991 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value)
2992 "Toggle `sql-pop-to-buffer-after-send-region'.
2993
2994 If given the optional parameter VALUE, sets
2995 `sql-toggle-pop-to-buffer-after-send-region' to VALUE."
2996 (interactive "P")
2997 (if value
2998 (setq sql-pop-to-buffer-after-send-region value)
2999 (setq sql-pop-to-buffer-after-send-region
3000 (null sql-pop-to-buffer-after-send-region))))
3001
3002 \f
3003
3004 ;;; Redirect output functions
3005
3006 (defun sql-redirect (command combuf &optional outbuf save-prior)
3007 "Execute the SQL command and send output to OUTBUF.
3008
3009 COMBUF must be an active SQL interactive buffer. OUTBUF may be
3010 an existing buffer, or the name of a non-existing buffer. If
3011 omitted the output is sent to a temporary buffer which will be
3012 killed after the command completes. COMMAND should be a string
3013 of commands accepted by the SQLi program."
3014
3015 (with-current-buffer combuf
3016 (let ((buf (get-buffer-create (or outbuf " *SQL-Redirect*")))
3017 (proc (get-buffer-process (current-buffer)))
3018 (comint-prompt-regexp (sql-get-product-feature sql-product
3019 :prompt-regexp))
3020 (start nil))
3021 (with-current-buffer buf
3022 (unless save-prior
3023 (erase-buffer))
3024 (goto-char (point-max))
3025 (setq start (point)))
3026
3027 ;; Run the command
3028 (comint-redirect-send-command-to-process command buf proc nil t)
3029 (while (null comint-redirect-completed)
3030 (accept-process-output nil 1))
3031
3032 ;; Remove echo if there was one
3033 (with-current-buffer buf
3034 (goto-char start)
3035 (when (looking-at (concat "^" (regexp-quote command) "[\\n]"))
3036 (delete-region (match-beginning 0) (match-end 0)))
3037 (goto-char start)))))
3038
3039 (defun sql-redirect-value (command combuf regexp &optional regexp-groups)
3040 "Execute the SQL command and return part of result.
3041
3042 COMBUF must be an active SQL interactive buffer. COMMAND should
3043 be a string of commands accepted by the SQLi program. From the
3044 output, the REGEXP is repeatedly matched and the list of
3045 REGEXP-GROUPS submatches is returned. This behaves much like
3046 \\[comint-redirect-results-list-from-process] but instead of
3047 returning a single submatch it returns a list of each submatch
3048 for each match."
3049
3050 (let ((outbuf " *SQL-Redirect-values*")
3051 (results nil))
3052 (sql-redirect command combuf outbuf nil)
3053 (with-current-buffer outbuf
3054 (while (re-search-forward regexp nil t)
3055 (push
3056 (cond
3057 ;; no groups-return all of them
3058 ((null regexp-groups)
3059 (let ((i 1)
3060 (r nil))
3061 (while (match-beginning i)
3062 (push (match-string i) r))
3063 (nreverse r)))
3064 ;; one group specified
3065 ((numberp regexp-groups)
3066 (match-string regexp-groups))
3067 ;; (buffer-substring-no-properties
3068 ;; (match-beginning regexp-groups)
3069 ;; (match-end regexp-groups)))
3070 ;; list of numbers; return the specified matches only
3071 ((consp regexp-groups)
3072 (mapcar (lambda (c)
3073 (cond
3074 ((numberp c) (match-string c))
3075 ((stringp c) (match-substitute-replacement c))
3076 (t (error "sql-redirect-value: unknown REGEXP-GROUPS value - %s" c))))
3077 regexp-groups))
3078 ;; String is specified; return replacement string
3079 ((stringp regexp-groups)
3080 (match-substitute-replacement regexp-groups))
3081 (t
3082 (error "sql-redirect-value: unknown REGEXP-GROUPS value - %s"
3083 regexp-groups)))
3084 results)))
3085 (nreverse results)))
3086
3087 \f
3088
3089 ;;; SQL mode -- uses SQL interactive mode
3090
3091 ;;;###autoload
3092 (defun sql-mode ()
3093 "Major mode to edit SQL.
3094
3095 You can send SQL statements to the SQLi buffer using
3096 \\[sql-send-region]. Such a buffer must exist before you can do this.
3097 See `sql-help' on how to create SQLi buffers.
3098
3099 \\{sql-mode-map}
3100 Customization: Entry to this mode runs the `sql-mode-hook'.
3101
3102 When you put a buffer in SQL mode, the buffer stores the last SQLi
3103 buffer created as its destination in the variable `sql-buffer'. This
3104 will be the buffer \\[sql-send-region] sends the region to. If this
3105 SQLi buffer is killed, \\[sql-send-region] is no longer able to
3106 determine where the strings should be sent to. You can set the
3107 value of `sql-buffer' using \\[sql-set-sqli-buffer].
3108
3109 For information on how to create multiple SQLi buffers, see
3110 `sql-interactive-mode'.
3111
3112 Note that SQL doesn't have an escape character unless you specify
3113 one. If you specify backslash as escape character in SQL,
3114 you must tell Emacs. Here's how to do that in your `~/.emacs' file:
3115
3116 \(add-hook 'sql-mode-hook
3117 (lambda ()
3118 (modify-syntax-entry ?\\\\ \".\" sql-mode-syntax-table)))"
3119 (interactive)
3120 (kill-all-local-variables)
3121 (setq major-mode 'sql-mode)
3122 (setq mode-name "SQL")
3123 (use-local-map sql-mode-map)
3124 (if sql-mode-menu
3125 (easy-menu-add sql-mode-menu)); XEmacs
3126 (set-syntax-table sql-mode-syntax-table)
3127 (make-local-variable 'font-lock-defaults)
3128 (make-local-variable 'sql-mode-font-lock-keywords)
3129 (make-local-variable 'comment-start)
3130 (setq comment-start "--")
3131 ;; Make each buffer in sql-mode remember the "current" SQLi buffer.
3132 (make-local-variable 'sql-buffer)
3133 ;; Add imenu support for sql-mode. Note that imenu-generic-expression
3134 ;; is buffer-local, so we don't need a local-variable for it. SQL is
3135 ;; case-insensitive, that's why we have to set imenu-case-fold-search.
3136 (setq imenu-generic-expression sql-imenu-generic-expression
3137 imenu-case-fold-search t)
3138 ;; Make `sql-send-paragraph' work on paragraphs that contain indented
3139 ;; lines.
3140 (make-local-variable 'paragraph-separate)
3141 (make-local-variable 'paragraph-start)
3142 (setq paragraph-separate "[\f]*$"
3143 paragraph-start "[\n\f]")
3144 ;; Abbrevs
3145 (setq local-abbrev-table sql-mode-abbrev-table)
3146 (setq abbrev-all-caps 1)
3147 ;; Run hook
3148 (run-mode-hooks 'sql-mode-hook)
3149 ;; Catch changes to sql-product and highlight accordingly
3150 (sql-highlight-product)
3151 (add-hook 'hack-local-variables-hook 'sql-highlight-product t t))
3152
3153 \f
3154
3155 ;;; SQL interactive mode
3156
3157 (put 'sql-interactive-mode 'mode-class 'special)
3158
3159 (defun sql-interactive-mode ()
3160 "Major mode to use a SQL interpreter interactively.
3161
3162 Do not call this function by yourself. The environment must be
3163 initialized by an entry function specific for the SQL interpreter.
3164 See `sql-help' for a list of available entry functions.
3165
3166 \\[comint-send-input] after the end of the process' output sends the
3167 text from the end of process to the end of the current line.
3168 \\[comint-send-input] before end of process output copies the current
3169 line minus the prompt to the end of the buffer and sends it.
3170 \\[comint-copy-old-input] just copies the current line.
3171 Use \\[sql-accumulate-and-indent] to enter multi-line statements.
3172
3173 If you want to make multiple SQL buffers, rename the `*SQL*' buffer
3174 using \\[rename-buffer] or \\[rename-uniquely] and start a new process.
3175 See `sql-help' for a list of available entry functions. The last buffer
3176 created by such an entry function is the current SQLi buffer. SQL
3177 buffers will send strings to the SQLi buffer current at the time of
3178 their creation. See `sql-mode' for details.
3179
3180 Sample session using two connections:
3181
3182 1. Create first SQLi buffer by calling an entry function.
3183 2. Rename buffer \"*SQL*\" to \"*Connection 1*\".
3184 3. Create a SQL buffer \"test1.sql\".
3185 4. Create second SQLi buffer by calling an entry function.
3186 5. Rename buffer \"*SQL*\" to \"*Connection 2*\".
3187 6. Create a SQL buffer \"test2.sql\".
3188
3189 Now \\[sql-send-region] in buffer \"test1.sql\" will send the region to
3190 buffer \"*Connection 1*\", \\[sql-send-region] in buffer \"test2.sql\"
3191 will send the region to buffer \"*Connection 2*\".
3192
3193 If you accidentally suspend your process, use \\[comint-continue-subjob]
3194 to continue it. On some operating systems, this will not work because
3195 the signals are not supported.
3196
3197 \\{sql-interactive-mode-map}
3198 Customization: Entry to this mode runs the hooks on `comint-mode-hook'
3199 and `sql-interactive-mode-hook' (in that order). Before each input, the
3200 hooks on `comint-input-filter-functions' are run. After each SQL
3201 interpreter output, the hooks on `comint-output-filter-functions' are
3202 run.
3203
3204 Variable `sql-input-ring-file-name' controls the initialization of the
3205 input ring history.
3206
3207 Variables `comint-output-filter-functions', a hook, and
3208 `comint-scroll-to-bottom-on-input' and
3209 `comint-scroll-to-bottom-on-output' control whether input and output
3210 cause the window to scroll to the end of the buffer.
3211
3212 If you want to make SQL buffers limited in length, add the function
3213 `comint-truncate-buffer' to `comint-output-filter-functions'.
3214
3215 Here is an example for your .emacs file. It keeps the SQLi buffer a
3216 certain length.
3217
3218 \(add-hook 'sql-interactive-mode-hook
3219 \(function (lambda ()
3220 \(setq comint-output-filter-functions 'comint-truncate-buffer))))
3221
3222 Here is another example. It will always put point back to the statement
3223 you entered, right above the output it created.
3224
3225 \(setq comint-output-filter-functions
3226 \(function (lambda (STR) (comint-show-output))))"
3227 (delay-mode-hooks (comint-mode))
3228
3229 ;; Get the `sql-product' for this interactive session.
3230 (set (make-local-variable 'sql-product)
3231 (or sql-interactive-product
3232 sql-product))
3233
3234 ;; Setup the mode.
3235 (setq major-mode 'sql-interactive-mode)
3236 (setq mode-name (concat "SQLi[" (or (sql-get-product-feature sql-product :name)
3237 (symbol-name sql-product)) "]"))
3238 (use-local-map sql-interactive-mode-map)
3239 (if sql-interactive-mode-menu
3240 (easy-menu-add sql-interactive-mode-menu)) ; XEmacs
3241 (set-syntax-table sql-mode-syntax-table)
3242 (make-local-variable 'sql-mode-font-lock-keywords)
3243 (make-local-variable 'font-lock-defaults)
3244
3245 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
3246 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
3247 ;; will have just one quote. Therefore syntactic hilighting is
3248 ;; disabled for interactive buffers. No imenu support.
3249 (sql-product-font-lock t nil)
3250
3251 ;; Enable commenting and uncommenting of the region.
3252 (make-local-variable 'comment-start)
3253 (setq comment-start "--")
3254 ;; Abbreviation table init and case-insensitive. It is not activated
3255 ;; by default.
3256 (setq local-abbrev-table sql-mode-abbrev-table)
3257 (setq abbrev-all-caps 1)
3258 ;; Exiting the process will call sql-stop.
3259 (set-process-sentinel (get-buffer-process (current-buffer)) 'sql-stop)
3260 ;; Save the connection name
3261 (make-local-variable 'sql-connection)
3262 ;; Create a usefull name for renaming this buffer later.
3263 (make-local-variable 'sql-alternate-buffer-name)
3264 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name))
3265 ;; User stuff. Initialize before the hook.
3266 (set (make-local-variable 'sql-prompt-regexp)
3267 (sql-get-product-feature sql-product :prompt-regexp))
3268 (set (make-local-variable 'sql-prompt-length)
3269 (sql-get-product-feature sql-product :prompt-length))
3270 (set (make-local-variable 'sql-prompt-cont-regexp)
3271 (sql-get-product-feature sql-product :prompt-cont-regexp))
3272 (make-local-variable 'sql-output-newline-count)
3273 (make-local-variable 'sql-output-by-send)
3274 (add-hook 'comint-preoutput-filter-functions
3275 'sql-interactive-remove-continuation-prompt nil t)
3276 (make-local-variable 'sql-input-ring-separator)
3277 (make-local-variable 'sql-input-ring-file-name)
3278 ;; Run the mode hook (along with comint's hooks).
3279 (run-mode-hooks 'sql-interactive-mode-hook)
3280 ;; Set comint based on user overrides.
3281 (setq comint-prompt-regexp
3282 (if sql-prompt-cont-regexp
3283 (concat "\\(" sql-prompt-regexp
3284 "\\|" sql-prompt-cont-regexp "\\)")
3285 sql-prompt-regexp))
3286 (setq left-margin sql-prompt-length)
3287 ;; Install input sender
3288 (set (make-local-variable 'comint-input-sender) 'sql-input-sender)
3289 ;; People wanting a different history file for each
3290 ;; buffer/process/client/whatever can change separator and file-name
3291 ;; on the sql-interactive-mode-hook.
3292 (setq comint-input-ring-separator sql-input-ring-separator
3293 comint-input-ring-file-name sql-input-ring-file-name)
3294 ;; Calling the hook before calling comint-read-input-ring allows users
3295 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook.
3296 (comint-read-input-ring t))
3297
3298 (defun sql-stop (process event)
3299 "Called when the SQL process is stopped.
3300
3301 Writes the input history to a history file using
3302 `comint-write-input-ring' and inserts a short message in the SQL buffer.
3303
3304 This function is a sentinel watching the SQL interpreter process.
3305 Sentinels will always get the two parameters PROCESS and EVENT."
3306 (comint-write-input-ring)
3307 (if (and (eq (current-buffer) sql-buffer)
3308 (not buffer-read-only))
3309 (insert (format "\nProcess %s %s\n" process event))
3310 (message "Process %s %s" process event)))
3311
3312 \f
3313
3314 ;;; Connection handling
3315
3316 ;;;###autoload
3317 (defun sql-connect (connection)
3318 "Connect to an interactive session using CONNECTION settings.
3319
3320 See `sql-connection-alist' to see how to define connections and
3321 their settings.
3322
3323 The user will not be prompted for any login parameters if a value
3324 is specified in the connection settings."
3325
3326 ;; Prompt for the connection from those defined in the alist
3327 (interactive
3328 (if sql-connection-alist
3329 (list
3330 (let ((completion-ignore-case t))
3331 (completing-read "Connection: "
3332 (mapcar (lambda (c) (car c))
3333 sql-connection-alist)
3334 nil t nil nil '(()))))
3335 nil))
3336
3337 ;; Are there connections defined
3338 (if sql-connection-alist
3339 ;; Was one selected
3340 (when connection
3341 ;; Get connection settings
3342 (let ((connect-set (assoc connection sql-connection-alist)))
3343 ;; Settings are defined
3344 (if connect-set
3345 ;; Set the desired parameters
3346 (eval `(let*
3347 (,@(cdr connect-set)
3348 ;; :sqli-login params variable
3349 (param-var (sql-get-product-feature sql-product
3350 :sqli-login nil t))
3351 ;; :sqli-login params value
3352 (login-params (sql-get-product-feature sql-product
3353 :sqli-login))
3354 ;; which params are in the connection
3355 (set-params (mapcar
3356 (lambda (v)
3357 (cond
3358 ((eq (car v) 'sql-user) 'user)
3359 ((eq (car v) 'sql-password) 'password)
3360 ((eq (car v) 'sql-server) 'server)
3361 ((eq (car v) 'sql-database) 'database)
3362 ((eq (car v) 'sql-port) 'port)
3363 (t (car v))))
3364 (cdr connect-set)))
3365 ;; the remaining params (w/o the connection params)
3366 (rem-params (sql-for-each-login
3367 login-params
3368 (lambda (token type arg)
3369 (unless (member token set-params)
3370 (if (or type arg)
3371 (list token type arg)
3372 token)))))
3373 ;; Remember the connection
3374 (sql-connection connection))
3375
3376 ;; Set the remaining parameters and start the
3377 ;; interactive session
3378 (eval `(let ((,param-var ',rem-params))
3379 (sql-product-interactive sql-product)))))
3380 (message "SQL Connection <%s> does not exist" connection)
3381 nil)))
3382 (message "No SQL Connections defined")
3383 nil))
3384
3385 (defun sql-save-connection (name)
3386 "Captures the connection information of the current SQLi session.
3387
3388 The information is appended to `sql-connection-alist' and
3389 optionally is saved to the user's init file."
3390
3391 (interactive "sNew connection name: ")
3392
3393 (if sql-connection
3394 (message "This session was started by a connection; it's already been saved.")
3395
3396 (let ((login (sql-get-product-feature sql-product :sqli-login))
3397 (alist sql-connection-alist)
3398 connect)
3399
3400 ;; Remove the existing connection if the user says so
3401 (when (and (assoc name alist)
3402 (yes-or-no-p (format "Replace connection definition <%s>? " name)))
3403 (setq alist (assq-delete-all name alist)))
3404
3405 ;; Add the new connection if it doesn't exist
3406 (if (assoc name alist)
3407 (message "Connection <%s> already exists" name)
3408 (setq connect
3409 (append (list name)
3410 (sql-for-each-login
3411 `(product ,@login)
3412 (lambda (token type arg)
3413 (cond
3414 ((eq token 'product) `(sql-product ',sql-product))
3415 ((eq token 'user) `(sql-user ,sql-user))
3416 ((eq token 'database) `(sql-database ,sql-database))
3417 ((eq token 'server) `(sql-server ,sql-server))
3418 ((eq token 'port) `(sql-port ,sql-port)))))))
3419
3420 (setq alist (append alist (list connect)))
3421
3422 ;; confirm whether we want to save the connections
3423 (if (yes-or-no-p "Save the connections for future sessions? ")
3424 (customize-save-variable 'sql-connection-alist alist)
3425 (customize-set-variable 'sql-connection-alist alist))))))
3426
3427 (defun sql-connection-menu-filter (tail)
3428 "Generates menu entries for using each connection."
3429 (append
3430 (mapcar
3431 (lambda (conn)
3432 (vector
3433 (format "Connection <%s>" (car conn))
3434 (list 'sql-connect (car conn))
3435 t))
3436 sql-connection-alist)
3437 tail))
3438
3439 \f
3440
3441 ;;; Entry functions for different SQL interpreters.
3442
3443 ;;;###autoload
3444 (defun sql-product-interactive (&optional product new-name)
3445 "Run PRODUCT interpreter as an inferior process.
3446
3447 If buffer `*SQL*' exists but no process is running, make a new process.
3448 If buffer exists and a process is running, just switch to buffer `*SQL*'.
3449
3450 To specify the SQL product, prefix the call with
3451 \\[universal-argument]. To set the buffer name as well, prefix
3452 the call to \\[sql-product-interactive] with
3453 \\[universal-argument] \\[universal-argument].
3454
3455 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3456 (interactive "P")
3457
3458 ;; Handle universal arguments if specified
3459 (when (not (or executing-kbd-macro noninteractive))
3460 (when (and (consp product)
3461 (not (cdr product))
3462 (numberp (car product)))
3463 (when (>= (car product) 16)
3464 (when (not new-name)
3465 (setq new-name '(4)))
3466 (setq product '(4)))))
3467
3468 ;; Get the value of product that we need
3469 (setq product
3470 (cond
3471 ((equal product '(4)) ; C-u, prompt for product
3472 (intern (completing-read "SQL product: "
3473 (mapcar (lambda (info) (symbol-name (car info)))
3474 sql-product-alist)
3475 nil 'require-match
3476 (or (and sql-product
3477 (symbol-name sql-product))
3478 "ansi"))))
3479 ((and product ; Product specified
3480 (symbolp product)) product)
3481 (t sql-product))) ; Default to sql-product
3482
3483 ;; If we have a product and it has a interactive mode
3484 (if product
3485 (when (sql-get-product-feature product :sqli-comint-func)
3486 ;; If no new name specified, fall back on sql-buffer if its for
3487 ;; the same product
3488 (if (and (not new-name)
3489 (sql-buffer-live-p sql-buffer product))
3490 (pop-to-buffer sql-buffer)
3491
3492 ;; We have a new name or sql-buffer doesn't exist or match
3493 ;; Start by remembering where we start
3494 (let* ((start-buffer (current-buffer))
3495 new-sqli-buffer)
3496
3497 ;; Get credentials.
3498 (apply 'sql-get-login (sql-get-product-feature product :sqli-login))
3499
3500 ;; Connect to database.
3501 (message "Login...")
3502 (funcall (sql-get-product-feature product :sqli-comint-func)
3503 product
3504 (sql-get-product-feature product :sqli-options))
3505
3506 ;; Set SQLi mode.
3507 (setq new-sqli-buffer (current-buffer))
3508 (let ((sql-interactive-product product))
3509 (sql-interactive-mode))
3510
3511 ;; Set the new buffer name
3512 (when new-name
3513 (sql-rename-buffer new-name))
3514
3515 ;; Set `sql-buffer' in the new buffer and the start buffer
3516 (setq sql-buffer (buffer-name new-sqli-buffer))
3517 (with-current-buffer start-buffer
3518 (setq sql-buffer (buffer-name new-sqli-buffer))
3519 (run-hooks 'sql-set-sqli-hook))
3520
3521 ;; All done.
3522 (message "Login...done")
3523 (pop-to-buffer sql-buffer))))
3524 (message "No default SQL product defined. Set `sql-product'.")))
3525
3526 (defun sql-comint (product params)
3527 "Set up a comint buffer to run the SQL processor.
3528
3529 PRODUCT is the SQL product. PARAMS is a list of strings which are
3530 passed as command line arguments."
3531 (let ((program (sql-get-product-feature product :sqli-program))
3532 (buf-name "SQL"))
3533 ;; Make sure buffer name is unique
3534 (when (get-buffer (format "*%s*" buf-name))
3535 (setq buf-name (format "SQL-%s" product))
3536 (when (get-buffer (format "*%s*" buf-name))
3537 (let ((i 1))
3538 (while (get-buffer (format "*%s*"
3539 (setq buf-name
3540 (format "SQL-%s%d" product i))))
3541 (setq i (1+ i))))))
3542 (set-buffer
3543 (apply 'make-comint buf-name program nil params))))
3544
3545 ;;;###autoload
3546 (defun sql-oracle (&optional buffer)
3547 "Run sqlplus by Oracle as an inferior process.
3548
3549 If buffer `*SQL*' exists but no process is running, make a new process.
3550 If buffer exists and a process is running, just switch to buffer
3551 `*SQL*'.
3552
3553 Interpreter used comes from variable `sql-oracle-program'. Login uses
3554 the variables `sql-user', `sql-password', and `sql-database' as
3555 defaults, if set. Additional command line parameters can be stored in
3556 the list `sql-oracle-options'.
3557
3558 The buffer is put in SQL interactive mode, giving commands for sending
3559 input. See `sql-interactive-mode'.
3560
3561 To set the buffer name directly, use \\[universal-argument]
3562 before \\[sql-oracle]. Once session has started,
3563 \\[sql-rename-buffer] can be called separately to rename the
3564 buffer.
3565
3566 To specify a coding system for converting non-ASCII characters
3567 in the input and output to the process, use \\[universal-coding-system-argument]
3568 before \\[sql-oracle]. You can also specify this with \\[set-buffer-process-coding-system]
3569 in the SQL buffer, after you start the process.
3570 The default comes from `process-coding-system-alist' and
3571 `default-process-coding-system'.
3572
3573 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3574 (interactive "P")
3575 (sql-product-interactive 'oracle buffer))
3576
3577 (defun sql-comint-oracle (product options)
3578 "Create comint buffer and connect to Oracle."
3579 ;; Produce user/password@database construct. Password without user
3580 ;; is meaningless; database without user/password is meaningless,
3581 ;; because "@param" will ask sqlplus to interpret the script
3582 ;; "param".
3583 (let ((parameter nil))
3584 (if (not (string= "" sql-user))
3585 (if (not (string= "" sql-password))
3586 (setq parameter (concat sql-user "/" sql-password))
3587 (setq parameter sql-user)))
3588 (if (and parameter (not (string= "" sql-database)))
3589 (setq parameter (concat parameter "@" sql-database)))
3590 (if parameter
3591 (setq parameter (nconc (list parameter) options))
3592 (setq parameter options))
3593 (sql-comint product parameter)))
3594
3595 \f
3596
3597 ;;;###autoload
3598 (defun sql-sybase (&optional buffer)
3599 "Run isql by Sybase as an inferior process.
3600
3601 If buffer `*SQL*' exists but no process is running, make a new process.
3602 If buffer exists and a process is running, just switch to buffer
3603 `*SQL*'.
3604
3605 Interpreter used comes from variable `sql-sybase-program'. Login uses
3606 the variables `sql-server', `sql-user', `sql-password', and
3607 `sql-database' as defaults, if set. Additional command line parameters
3608 can be stored in the list `sql-sybase-options'.
3609
3610 The buffer is put in SQL interactive mode, giving commands for sending
3611 input. See `sql-interactive-mode'.
3612
3613 To set the buffer name directly, use \\[universal-argument]
3614 before \\[sql-sybase]. Once session has started,
3615 \\[sql-rename-buffer] can be called separately to rename the
3616 buffer.
3617
3618 To specify a coding system for converting non-ASCII characters
3619 in the input and output to the process, use \\[universal-coding-system-argument]
3620 before \\[sql-sybase]. You can also specify this with \\[set-buffer-process-coding-system]
3621 in the SQL buffer, after you start the process.
3622 The default comes from `process-coding-system-alist' and
3623 `default-process-coding-system'.
3624
3625 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3626 (interactive "P")
3627 (sql-product-interactive 'sybase buffer))
3628
3629 (defun sql-comint-sybase (product options)
3630 "Create comint buffer and connect to Sybase."
3631 ;; Put all parameters to the program (if defined) in a list and call
3632 ;; make-comint.
3633 (let ((params options))
3634 (if (not (string= "" sql-server))
3635 (setq params (append (list "-S" sql-server) params)))
3636 (if (not (string= "" sql-database))
3637 (setq params (append (list "-D" sql-database) params)))
3638 (if (not (string= "" sql-password))
3639 (setq params (append (list "-P" sql-password) params)))
3640 (if (not (string= "" sql-user))
3641 (setq params (append (list "-U" sql-user) params)))
3642 (sql-comint product params)))
3643
3644 \f
3645
3646 ;;;###autoload
3647 (defun sql-informix (&optional buffer)
3648 "Run dbaccess by Informix as an inferior process.
3649
3650 If buffer `*SQL*' exists but no process is running, make a new process.
3651 If buffer exists and a process is running, just switch to buffer
3652 `*SQL*'.
3653
3654 Interpreter used comes from variable `sql-informix-program'. Login uses
3655 the variable `sql-database' as default, if set.
3656
3657 The buffer is put in SQL interactive mode, giving commands for sending
3658 input. See `sql-interactive-mode'.
3659
3660 To set the buffer name directly, use \\[universal-argument]
3661 before \\[sql-informix]. Once session has started,
3662 \\[sql-rename-buffer] can be called separately to rename the
3663 buffer.
3664
3665 To specify a coding system for converting non-ASCII characters
3666 in the input and output to the process, use \\[universal-coding-system-argument]
3667 before \\[sql-informix]. You can also specify this with \\[set-buffer-process-coding-system]
3668 in the SQL buffer, after you start the process.
3669 The default comes from `process-coding-system-alist' and
3670 `default-process-coding-system'.
3671
3672 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3673 (interactive "P")
3674 (sql-product-interactive 'informix buffer))
3675
3676 (defun sql-comint-informix (product options)
3677 "Create comint buffer and connect to Informix."
3678 ;; username and password are ignored.
3679 (let ((db (if (string= "" sql-database)
3680 "-"
3681 (if (string= "" sql-server)
3682 sql-database
3683 (concat sql-database "@" sql-server)))))
3684 (sql-comint product (append `(,db "-") options))))
3685
3686 \f
3687
3688 ;;;###autoload
3689 (defun sql-sqlite (&optional buffer)
3690 "Run sqlite as an inferior process.
3691
3692 SQLite is free software.
3693
3694 If buffer `*SQL*' exists but no process is running, make a new process.
3695 If buffer exists and a process is running, just switch to buffer
3696 `*SQL*'.
3697
3698 Interpreter used comes from variable `sql-sqlite-program'. Login uses
3699 the variables `sql-user', `sql-password', `sql-database', and
3700 `sql-server' as defaults, if set. Additional command line parameters
3701 can be stored in the list `sql-sqlite-options'.
3702
3703 The buffer is put in SQL interactive mode, giving commands for sending
3704 input. See `sql-interactive-mode'.
3705
3706 To set the buffer name directly, use \\[universal-argument]
3707 before \\[sql-sqlite]. Once session has started,
3708 \\[sql-rename-buffer] can be called separately to rename the
3709 buffer.
3710
3711 To specify a coding system for converting non-ASCII characters
3712 in the input and output to the process, use \\[universal-coding-system-argument]
3713 before \\[sql-sqlite]. You can also specify this with \\[set-buffer-process-coding-system]
3714 in the SQL buffer, after you start the process.
3715 The default comes from `process-coding-system-alist' and
3716 `default-process-coding-system'.
3717
3718 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3719 (interactive "P")
3720 (sql-product-interactive 'sqlite buffer))
3721
3722 (defun sql-comint-sqlite (product options)
3723 "Create comint buffer and connect to SQLite."
3724 ;; Put all parameters to the program (if defined) in a list and call
3725 ;; make-comint.
3726 (let ((params))
3727 (if (not (string= "" sql-database))
3728 (setq params (append (list (expand-file-name sql-database))
3729 params)))
3730 (setq params (append options params))
3731 (sql-comint product params)))
3732
3733 \f
3734
3735 ;;;###autoload
3736 (defun sql-mysql (&optional buffer)
3737 "Run mysql by TcX as an inferior process.
3738
3739 Mysql versions 3.23 and up are free software.
3740
3741 If buffer `*SQL*' exists but no process is running, make a new process.
3742 If buffer exists and a process is running, just switch to buffer
3743 `*SQL*'.
3744
3745 Interpreter used comes from variable `sql-mysql-program'. Login uses
3746 the variables `sql-user', `sql-password', `sql-database', and
3747 `sql-server' as defaults, if set. Additional command line parameters
3748 can be stored in the list `sql-mysql-options'.
3749
3750 The buffer is put in SQL interactive mode, giving commands for sending
3751 input. See `sql-interactive-mode'.
3752
3753 To set the buffer name directly, use \\[universal-argument]
3754 before \\[sql-mysql]. Once session has started,
3755 \\[sql-rename-buffer] can be called separately to rename the
3756 buffer.
3757
3758 To specify a coding system for converting non-ASCII characters
3759 in the input and output to the process, use \\[universal-coding-system-argument]
3760 before \\[sql-mysql]. You can also specify this with \\[set-buffer-process-coding-system]
3761 in the SQL buffer, after you start the process.
3762 The default comes from `process-coding-system-alist' and
3763 `default-process-coding-system'.
3764
3765 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3766 (interactive "P")
3767 (sql-product-interactive 'mysql buffer))
3768
3769 (defun sql-comint-mysql (product options)
3770 "Create comint buffer and connect to MySQL."
3771 ;; Put all parameters to the program (if defined) in a list and call
3772 ;; make-comint.
3773 (let ((params))
3774 (if (not (string= "" sql-database))
3775 (setq params (append (list sql-database) params)))
3776 (if (not (string= "" sql-server))
3777 (setq params (append (list (concat "--host=" sql-server)) params)))
3778 (if (not (= 0 sql-port))
3779 (setq params (append (list (concat "--port=" (number-to-string sql-port))) params)))
3780 (if (not (string= "" sql-password))
3781 (setq params (append (list (concat "--password=" sql-password)) params)))
3782 (if (not (string= "" sql-user))
3783 (setq params (append (list (concat "--user=" sql-user)) params)))
3784 (setq params (append options params))
3785 (sql-comint product params)))
3786
3787 \f
3788
3789 ;;;###autoload
3790 (defun sql-solid (&optional buffer)
3791 "Run solsql by Solid as an inferior process.
3792
3793 If buffer `*SQL*' exists but no process is running, make a new process.
3794 If buffer exists and a process is running, just switch to buffer
3795 `*SQL*'.
3796
3797 Interpreter used comes from variable `sql-solid-program'. Login uses
3798 the variables `sql-user', `sql-password', and `sql-server' as
3799 defaults, if set.
3800
3801 The buffer is put in SQL interactive mode, giving commands for sending
3802 input. See `sql-interactive-mode'.
3803
3804 To set the buffer name directly, use \\[universal-argument]
3805 before \\[sql-solid]. Once session has started,
3806 \\[sql-rename-buffer] can be called separately to rename the
3807 buffer.
3808
3809 To specify a coding system for converting non-ASCII characters
3810 in the input and output to the process, use \\[universal-coding-system-argument]
3811 before \\[sql-solid]. You can also specify this with \\[set-buffer-process-coding-system]
3812 in the SQL buffer, after you start the process.
3813 The default comes from `process-coding-system-alist' and
3814 `default-process-coding-system'.
3815
3816 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3817 (interactive "P")
3818 (sql-product-interactive 'solid buffer))
3819
3820 (defun sql-comint-solid (product options)
3821 "Create comint buffer and connect to Solid."
3822 ;; Put all parameters to the program (if defined) in a list and call
3823 ;; make-comint.
3824 (let ((params options))
3825 ;; It only makes sense if both username and password are there.
3826 (if (not (or (string= "" sql-user)
3827 (string= "" sql-password)))
3828 (setq params (append (list sql-user sql-password) params)))
3829 (if (not (string= "" sql-server))
3830 (setq params (append (list sql-server) params)))
3831 (sql-comint product params)))
3832
3833 \f
3834
3835 ;;;###autoload
3836 (defun sql-ingres (&optional buffer)
3837 "Run sql by Ingres as an inferior process.
3838
3839 If buffer `*SQL*' exists but no process is running, make a new process.
3840 If buffer exists and a process is running, just switch to buffer
3841 `*SQL*'.
3842
3843 Interpreter used comes from variable `sql-ingres-program'. Login uses
3844 the variable `sql-database' as default, if set.
3845
3846 The buffer is put in SQL interactive mode, giving commands for sending
3847 input. See `sql-interactive-mode'.
3848
3849 To set the buffer name directly, use \\[universal-argument]
3850 before \\[sql-ingres]. Once session has started,
3851 \\[sql-rename-buffer] can be called separately to rename the
3852 buffer.
3853
3854 To specify a coding system for converting non-ASCII characters
3855 in the input and output to the process, use \\[universal-coding-system-argument]
3856 before \\[sql-ingres]. You can also specify this with \\[set-buffer-process-coding-system]
3857 in the SQL buffer, after you start the process.
3858 The default comes from `process-coding-system-alist' and
3859 `default-process-coding-system'.
3860
3861 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3862 (interactive "P")
3863 (sql-product-interactive 'ingres buffer))
3864
3865 (defun sql-comint-ingres (product options)
3866 "Create comint buffer and connect to Ingres."
3867 ;; username and password are ignored.
3868 (sql-comint product
3869 (append (if (string= "" sql-database)
3870 nil
3871 (list sql-database))
3872 options)))
3873
3874 \f
3875
3876 ;;;###autoload
3877 (defun sql-ms (&optional buffer)
3878 "Run osql by Microsoft as an inferior process.
3879
3880 If buffer `*SQL*' exists but no process is running, make a new process.
3881 If buffer exists and a process is running, just switch to buffer
3882 `*SQL*'.
3883
3884 Interpreter used comes from variable `sql-ms-program'. Login uses the
3885 variables `sql-user', `sql-password', `sql-database', and `sql-server'
3886 as defaults, if set. Additional command line parameters can be stored
3887 in the list `sql-ms-options'.
3888
3889 The buffer is put in SQL interactive mode, giving commands for sending
3890 input. See `sql-interactive-mode'.
3891
3892 To set the buffer name directly, use \\[universal-argument]
3893 before \\[sql-ms]. Once session has started,
3894 \\[sql-rename-buffer] can be called separately to rename the
3895 buffer.
3896
3897 To specify a coding system for converting non-ASCII characters
3898 in the input and output to the process, use \\[universal-coding-system-argument]
3899 before \\[sql-ms]. You can also specify this with \\[set-buffer-process-coding-system]
3900 in the SQL buffer, after you start the process.
3901 The default comes from `process-coding-system-alist' and
3902 `default-process-coding-system'.
3903
3904 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3905 (interactive "P")
3906 (sql-product-interactive 'ms buffer))
3907
3908 (defun sql-comint-ms (product options)
3909 "Create comint buffer and connect to Microsoft SQL Server."
3910 ;; Put all parameters to the program (if defined) in a list and call
3911 ;; make-comint.
3912 (let ((params options))
3913 (if (not (string= "" sql-server))
3914 (setq params (append (list "-S" sql-server) params)))
3915 (if (not (string= "" sql-database))
3916 (setq params (append (list "-d" sql-database) params)))
3917 (if (not (string= "" sql-user))
3918 (setq params (append (list "-U" sql-user) params)))
3919 (if (not (string= "" sql-password))
3920 (setq params (append (list "-P" sql-password) params))
3921 (if (string= "" sql-user)
3922 ;; if neither user nor password is provided, use system
3923 ;; credentials.
3924 (setq params (append (list "-E") params))
3925 ;; If -P is passed to ISQL as the last argument without a
3926 ;; password, it's considered null.
3927 (setq params (append params (list "-P")))))
3928 (sql-comint product params)))
3929
3930 \f
3931
3932 ;;;###autoload
3933 (defun sql-postgres (&optional buffer)
3934 "Run psql by Postgres as an inferior process.
3935
3936 If buffer `*SQL*' exists but no process is running, make a new process.
3937 If buffer exists and a process is running, just switch to buffer
3938 `*SQL*'.
3939
3940 Interpreter used comes from variable `sql-postgres-program'. Login uses
3941 the variables `sql-database' and `sql-server' as default, if set.
3942 Additional command line parameters can be stored in the list
3943 `sql-postgres-options'.
3944
3945 The buffer is put in SQL interactive mode, giving commands for sending
3946 input. See `sql-interactive-mode'.
3947
3948 To set the buffer name directly, use \\[universal-argument]
3949 before \\[sql-postgres]. Once session has started,
3950 \\[sql-rename-buffer] can be called separately to rename the
3951 buffer.
3952
3953 To specify a coding system for converting non-ASCII characters
3954 in the input and output to the process, use \\[universal-coding-system-argument]
3955 before \\[sql-postgres]. You can also specify this with \\[set-buffer-process-coding-system]
3956 in the SQL buffer, after you start the process.
3957 The default comes from `process-coding-system-alist' and
3958 `default-process-coding-system'. If your output lines end with ^M,
3959 your might try undecided-dos as a coding system. If this doesn't help,
3960 Try to set `comint-output-filter-functions' like this:
3961
3962 \(setq comint-output-filter-functions (append comint-output-filter-functions
3963 '(comint-strip-ctrl-m)))
3964
3965 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
3966 (interactive "P")
3967 (sql-product-interactive 'postgres buffer))
3968
3969 (defun sql-comint-postgres (product options)
3970 "Create comint buffer and connect to Postgres."
3971 ;; username and password are ignored. Mark Stosberg suggest to add
3972 ;; the database at the end. Jason Beegan suggest using --pset and
3973 ;; pager=off instead of \\o|cat. The later was the solution by
3974 ;; Gregor Zych. Jason's suggestion is the default value for
3975 ;; sql-postgres-options.
3976 (let ((params options))
3977 (if (not (string= "" sql-database))
3978 (setq params (append params (list sql-database))))
3979 (if (not (string= "" sql-server))
3980 (setq params (append (list "-h" sql-server) params)))
3981 (if (not (string= "" sql-user))
3982 (setq params (append (list "-U" sql-user) params)))
3983 (sql-comint product params)))
3984
3985 \f
3986
3987 ;;;###autoload
3988 (defun sql-interbase (&optional buffer)
3989 "Run isql by Interbase as an inferior process.
3990
3991 If buffer `*SQL*' exists but no process is running, make a new process.
3992 If buffer exists and a process is running, just switch to buffer
3993 `*SQL*'.
3994
3995 Interpreter used comes from variable `sql-interbase-program'. Login
3996 uses the variables `sql-user', `sql-password', and `sql-database' as
3997 defaults, if set.
3998
3999 The buffer is put in SQL interactive mode, giving commands for sending
4000 input. See `sql-interactive-mode'.
4001
4002 To set the buffer name directly, use \\[universal-argument]
4003 before \\[sql-interbase]. Once session has started,
4004 \\[sql-rename-buffer] can be called separately to rename the
4005 buffer.
4006
4007 To specify a coding system for converting non-ASCII characters
4008 in the input and output to the process, use \\[universal-coding-system-argument]
4009 before \\[sql-interbase]. You can also specify this with \\[set-buffer-process-coding-system]
4010 in the SQL buffer, after you start the process.
4011 The default comes from `process-coding-system-alist' and
4012 `default-process-coding-system'.
4013
4014 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4015 (interactive "P")
4016 (sql-product-interactive 'interbase buffer))
4017
4018 (defun sql-comint-interbase (product options)
4019 "Create comint buffer and connect to Interbase."
4020 ;; Put all parameters to the program (if defined) in a list and call
4021 ;; make-comint.
4022 (let ((params options))
4023 (if (not (string= "" sql-user))
4024 (setq params (append (list "-u" sql-user) params)))
4025 (if (not (string= "" sql-password))
4026 (setq params (append (list "-p" sql-password) params)))
4027 (if (not (string= "" sql-database))
4028 (setq params (cons sql-database params))) ; add to the front!
4029 (sql-comint product params)))
4030
4031 \f
4032
4033 ;;;###autoload
4034 (defun sql-db2 (&optional buffer)
4035 "Run db2 by IBM as an inferior process.
4036
4037 If buffer `*SQL*' exists but no process is running, make a new process.
4038 If buffer exists and a process is running, just switch to buffer
4039 `*SQL*'.
4040
4041 Interpreter used comes from variable `sql-db2-program'. There is not
4042 automatic login.
4043
4044 The buffer is put in SQL interactive mode, giving commands for sending
4045 input. See `sql-interactive-mode'.
4046
4047 If you use \\[sql-accumulate-and-indent] to send multiline commands to
4048 db2, newlines will be escaped if necessary. If you don't want that, set
4049 `comint-input-sender' back to `comint-simple-send' by writing an after
4050 advice. See the elisp manual for more information.
4051
4052 To set the buffer name directly, use \\[universal-argument]
4053 before \\[sql-db2]. Once session has started,
4054 \\[sql-rename-buffer] can be called separately to rename the
4055 buffer.
4056
4057 To specify a coding system for converting non-ASCII characters
4058 in the input and output to the process, use \\[universal-coding-system-argument]
4059 before \\[sql-db2]. You can also specify this with \\[set-buffer-process-coding-system]
4060 in the SQL buffer, after you start the process.
4061 The default comes from `process-coding-system-alist' and
4062 `default-process-coding-system'.
4063
4064 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4065 (interactive "P")
4066 (sql-product-interactive 'db2 buffer))
4067
4068 (defun sql-comint-db2 (product options)
4069 "Create comint buffer and connect to DB2."
4070 ;; Put all parameters to the program (if defined) in a list and call
4071 ;; make-comint.
4072 (sql-comint product options)
4073 )
4074
4075 ;;;###autoload
4076 (defun sql-linter (&optional buffer)
4077 "Run inl by RELEX as an inferior process.
4078
4079 If buffer `*SQL*' exists but no process is running, make a new process.
4080 If buffer exists and a process is running, just switch to buffer
4081 `*SQL*'.
4082
4083 Interpreter used comes from variable `sql-linter-program' - usually `inl'.
4084 Login uses the variables `sql-user', `sql-password', `sql-database' and
4085 `sql-server' as defaults, if set. Additional command line parameters
4086 can be stored in the list `sql-linter-options'. Run inl -h to get help on
4087 parameters.
4088
4089 `sql-database' is used to set the LINTER_MBX environment variable for
4090 local connections, `sql-server' refers to the server name from the
4091 `nodetab' file for the network connection (dbc_tcp or friends must run
4092 for this to work). If `sql-password' is an empty string, inl will use
4093 an empty password.
4094
4095 The buffer is put in SQL interactive mode, giving commands for sending
4096 input. See `sql-interactive-mode'.
4097
4098 To set the buffer name directly, use \\[universal-argument]
4099 before \\[sql-linter]. Once session has started,
4100 \\[sql-rename-buffer] can be called separately to rename the
4101 buffer.
4102
4103 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4104 (interactive "P")
4105 (sql-product-interactive 'linter buffer))
4106
4107 (defun sql-comint-linter (product options)
4108 "Create comint buffer and connect to Linter."
4109 ;; Put all parameters to the program (if defined) in a list and call
4110 ;; make-comint.
4111 (let ((params options)
4112 (login nil)
4113 (old-mbx (getenv "LINTER_MBX")))
4114 (if (not (string= "" sql-user))
4115 (setq login (concat sql-user "/" sql-password)))
4116 (setq params (append (list "-u" login) params))
4117 (if (not (string= "" sql-server))
4118 (setq params (append (list "-n" sql-server) params)))
4119 (if (string= "" sql-database)
4120 (setenv "LINTER_MBX" nil)
4121 (setenv "LINTER_MBX" sql-database))
4122 (sql-comint product params)
4123 (setenv "LINTER_MBX" old-mbx)))
4124
4125 \f
4126
4127 (provide 'sql)
4128
4129 ;; arch-tag: 7e1fa1c4-9ca2-402e-87d2-83a5eccb7ac3
4130 ;;; sql.el ends here
4131