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