1 ;;; sql.el --- specialized comint.el for SQL interpreters -*- lexical-binding: t -*-
3 ;; Copyright (C) 1998-2017 Free Software Foundation, Inc.
5 ;; Author: Alex Schroeder <alex@gnu.org>
6 ;; Maintainer: Michael Mauger <michael@mauger.com>
8 ;; Keywords: comm languages processes
9 ;; URL: http://savannah.gnu.org/projects/emacs/
11 ;; This file is part of GNU Emacs.
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.
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.
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/>.
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).
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.
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.
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.
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
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).
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
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.
77 ;; For documentation on the functionality provided by comint mode, and
78 ;; the hooks available for customizing it, see the file `comint.el'.
80 ;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and
81 ;; `imenu-add-menubar-index'.
85 ;; sql-ms now uses osql instead of isql. Osql flushes its error
86 ;; stream more frequently than isql so that error messages are
87 ;; available. There is no prompt and some output still is buffered.
88 ;; This improves the interaction under Emacs but it still is somewhat
91 ;; Quoted identifiers are not supported for highlighting. Most
92 ;; databases support the use of double quoted strings in place of
93 ;; identifiers; ms (Microsoft SQLServer) also supports identifiers
94 ;; enclosed within brackets [].
98 ;; To add support for additional SQL products the following steps
99 ;; must be followed ("xyz" is the name of the product in the examples
102 ;; 1) Add the product to the list of known products.
104 ;; (sql-add-product 'xyz "XyzDB"
105 ;; '(:free-software t))
107 ;; 2) Define font lock settings. All ANSI keywords will be
108 ;; highlighted automatically, so only product specific keywords
109 ;; need to be defined here.
111 ;; (defvar my-sql-mode-xyz-font-lock-keywords
112 ;; '(("\\b\\(red\\|orange\\|yellow\\)\\b"
113 ;; . font-lock-keyword-face))
114 ;; "XyzDB SQL keywords used by font-lock.")
116 ;; (sql-set-product-feature 'xyz
118 ;; 'my-sql-mode-xyz-font-lock-keywords)
120 ;; 3) Define any special syntax characters including comments and
121 ;; identifier characters.
123 ;; (sql-set-product-feature 'xyz
124 ;; :syntax-alist ((?# . "_")))
126 ;; 4) Define the interactive command interpreter for the database
129 ;; (defcustom my-sql-xyz-program "ixyz"
130 ;; "Command to start ixyz by XyzDB."
134 ;; (sql-set-product-feature 'xyz
135 ;; :sqli-program 'my-sql-xyz-program)
136 ;; (sql-set-product-feature 'xyz
137 ;; :prompt-regexp "^xyzdb> ")
138 ;; (sql-set-product-feature 'xyz
141 ;; 5) Define login parameters and command line formatting.
143 ;; (defcustom my-sql-xyz-login-params '(user password server database)
144 ;; "Login parameters to needed to connect to XyzDB."
145 ;; :type 'sql-login-params
148 ;; (sql-set-product-feature 'xyz
149 ;; :sqli-login 'my-sql-xyz-login-params)
151 ;; (defcustom my-sql-xyz-options '("-X" "-Y" "-Z")
152 ;; "List of additional options for `sql-xyz-program'."
153 ;; :type '(repeat string)
156 ;; (sql-set-product-feature 'xyz
157 ;; :sqli-options 'my-sql-xyz-options))
159 ;; (defun my-sql-comint-xyz (product options)
160 ;; "Connect ti XyzDB in a comint buffer."
162 ;; ;; Do something with `sql-user', `sql-password',
163 ;; ;; `sql-database', and `sql-server'.
166 ;; (if (not (string= "" sql-user))
167 ;; (list "-U" sql-user))
168 ;; (if (not (string= "" sql-password))
169 ;; (list "-P" sql-password))
170 ;; (if (not (string= "" sql-database))
171 ;; (list "-D" sql-database))
172 ;; (if (not (string= "" sql-server))
173 ;; (list "-S" sql-server))
175 ;; (sql-comint product params)))
177 ;; (sql-set-product-feature 'xyz
178 ;; :sqli-comint-func 'my-sql-comint-xyz)
180 ;; 6) Define a convenience function to invoke the SQL interpreter.
182 ;; (defun my-sql-xyz (&optional buffer)
183 ;; "Run ixyz by XyzDB as an inferior process."
185 ;; (sql-product-interactive 'xyz buffer))
189 ;; Improve keyword highlighting for individual products. I have tried
190 ;; to update those database that I use. Feel free to send me updates,
191 ;; or direct me to the reference manuals for your favorite database.
193 ;; When there are no keywords defined, the ANSI keywords are
194 ;; highlighted. ANSI keywords are highlighted even if the keyword is
195 ;; not used for your current product. This should help identify
196 ;; portability concerns.
198 ;; Add different highlighting levels.
200 ;; Add support for listing available tables or the columns in a table.
202 ;;; Thanks to all the people who helped me out:
204 ;; Alex Schroeder <alex@gnu.org> -- the original author
205 ;; Kai Blauberg <kai.blauberg@metla.fi>
206 ;; <ibalaban@dalet.com>
207 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il>
208 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
209 ;; nino <nino@inform.dk>
210 ;; Berend de Boer <berend@pobox.com>
211 ;; Adam Jenkins <adam@thejenkins.org>
212 ;; Michael Mauger <michael@mauger.com> -- improved product support
213 ;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support
214 ;; Harald Maier <maierh@myself.com> -- sql-send-string
215 ;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections;
217 ;; Paul Sleigh <bat@flurf.net> -- MySQL keyword enhancement
218 ;; Andrew Schein <andrew@andrewschein.com> -- sql-port bug
219 ;; Ian Bjorhovde <idbjorh@dataproxy.com> -- db2 escape newlines
220 ;; incorrectly enabled by default
221 ;; Roman Scherer <roman.scherer@nugg.ad> -- Connection documentation
222 ;; Mark Wilkinson <wilkinsonmr@gmail.com> -- file-local variables ignored
231 ;; Need the following to allow GNU Emacs 19 to compile the file.
233 (require 'regexp-opt
))
238 (defvar font-lock-keyword-face
)
239 (defvar font-lock-set-defaults
)
240 (defvar font-lock-string-face
)
242 ;;; Allow customization
245 "Running a SQL interpreter from within Emacs buffers."
250 ;; These five variables will be used as defaults, if set.
252 (defcustom sql-user
""
258 (defcustom sql-password
""
260 If you customize this, the value will be stored in your init
261 file. Since that is a plaintext file, this could be dangerous."
266 (defcustom sql-database
""
272 (defcustom sql-server
""
273 "Default server or host."
278 (defcustom sql-port
0
279 "Default port for connecting to a MySQL or Postgres server."
285 (defcustom sql-default-directory nil
286 "Default directory for SQL processes."
288 :type
'(choice (const nil
) string
)
292 ;; Login parameter type
294 (define-widget 'sql-login-params
'lazy
295 "Widget definition of the login parameters list"
296 :tag
"Login Parameters"
297 :type
'(set :tag
"Login Parameters"
301 (list :tag
"Specify a default"
304 :inline t
(const :default
) string
)))
306 (choice :tag
"server"
309 (list :tag
"Specify a default"
312 :inline t
(const :default
) string
))
314 (const :format
"" server
)
315 (const :format
"" :file
)
317 (list :tag
"completion"
318 (const :format
"" server
)
319 (const :format
"" :completion
)
321 :match-alternatives
(listp stringp
))))
322 (choice :tag
"database"
325 (list :tag
"Specify a default"
328 :inline t
(const :default
) string
))
330 (const :format
"" database
)
331 (const :format
"" :file
)
333 (list :tag
"completion"
334 (const :format
"" database
)
335 (const :format
"" :completion
)
337 :match-alternatives
(listp stringp
))))
340 ;; SQL Product support
342 (defvar sql-interactive-product nil
343 "Product under `sql-interactive-mode'.")
345 (defvar sql-connection nil
346 "Connection name if interactive session started by `sql-connect'.")
348 (defvar sql-product-alist
351 :font-lock sql-mode-ansi-font-lock-keywords
352 :statement sql-ansi-statement-starters
)
356 :font-lock sql-mode-db2-font-lock-keywords
357 :sqli-program sql-db2-program
358 :sqli-options sql-db2-options
359 :sqli-login sql-db2-login-params
360 :sqli-comint-func sql-comint-db2
361 :prompt-regexp
"^db2 => "
363 :prompt-cont-regexp
"^db2 (cont\\.) => "
364 :input-filter sql-escape-newlines-filter
)
368 :font-lock sql-mode-informix-font-lock-keywords
369 :sqli-program sql-informix-program
370 :sqli-options sql-informix-options
371 :sqli-login sql-informix-login-params
372 :sqli-comint-func sql-comint-informix
375 :syntax-alist
((?
{ .
"<") (?
} .
">")))
379 :font-lock sql-mode-ingres-font-lock-keywords
380 :sqli-program sql-ingres-program
381 :sqli-options sql-ingres-options
382 :sqli-login sql-ingres-login-params
383 :sqli-comint-func sql-comint-ingres
384 :prompt-regexp
"^\\* "
386 :prompt-cont-regexp
"^\\* ")
390 :font-lock sql-mode-interbase-font-lock-keywords
391 :sqli-program sql-interbase-program
392 :sqli-options sql-interbase-options
393 :sqli-login sql-interbase-login-params
394 :sqli-comint-func sql-comint-interbase
395 :prompt-regexp
"^SQL> "
400 :font-lock sql-mode-linter-font-lock-keywords
401 :sqli-program sql-linter-program
402 :sqli-options sql-linter-options
403 :sqli-login sql-linter-login-params
404 :sqli-comint-func sql-comint-linter
405 :prompt-regexp
"^SQL>"
410 :font-lock sql-mode-ms-font-lock-keywords
411 :sqli-program sql-ms-program
412 :sqli-options sql-ms-options
413 :sqli-login sql-ms-login-params
414 :sqli-comint-func sql-comint-ms
415 :prompt-regexp
"^[0-9]*>"
417 :syntax-alist
((?
@ .
"_"))
418 :terminator
("^go" .
"go"))
423 :font-lock sql-mode-mysql-font-lock-keywords
424 :sqli-program sql-mysql-program
425 :sqli-options sql-mysql-options
426 :sqli-login sql-mysql-login-params
427 :sqli-comint-func sql-comint-mysql
428 :list-all
"SHOW TABLES;"
429 :list-table
"DESCRIBE %s;"
430 :prompt-regexp
"^mysql> "
432 :prompt-cont-regexp
"^ -> "
433 :syntax-alist
((?
# .
"< b"))
434 :input-filter sql-remove-tabs-filter
)
438 :font-lock sql-mode-oracle-font-lock-keywords
439 :sqli-program sql-oracle-program
440 :sqli-options sql-oracle-options
441 :sqli-login sql-oracle-login-params
442 :sqli-comint-func sql-comint-oracle
443 :list-all sql-oracle-list-all
444 :list-table sql-oracle-list-table
445 :completion-object sql-oracle-completion-object
446 :prompt-regexp
"^SQL> "
448 :prompt-cont-regexp
"^\\(?:[ ][ ][1-9]\\|[ ][1-9][0-9]\\|[1-9][0-9]\\{2\\}\\)[ ]\\{2\\}"
449 :statement sql-oracle-statement-starters
450 :syntax-alist
((?$ .
"_") (?
# .
"_"))
451 :terminator
("\\(^/\\|;\\)$" .
"/")
452 :input-filter sql-placeholders-filter
)
457 :font-lock sql-mode-postgres-font-lock-keywords
458 :sqli-program sql-postgres-program
459 :sqli-options sql-postgres-options
460 :sqli-login sql-postgres-login-params
461 :sqli-comint-func sql-comint-postgres
462 :list-all
("\\d+" .
"\\dS+")
463 :list-table
("\\d+ %s" .
"\\dS+ %s")
464 :completion-object sql-postgres-completion-object
465 :prompt-regexp
"^\\w*=[#>] "
467 :prompt-cont-regexp
"^\\w*[-(][#>] "
468 :input-filter sql-remove-tabs-filter
469 :terminator
("\\(^\\s-*\\\\g$\\|;\\)" .
"\\g"))
473 :font-lock sql-mode-solid-font-lock-keywords
474 :sqli-program sql-solid-program
475 :sqli-options sql-solid-options
476 :sqli-login sql-solid-login-params
477 :sqli-comint-func sql-comint-solid
484 :font-lock sql-mode-sqlite-font-lock-keywords
485 :sqli-program sql-sqlite-program
486 :sqli-options sql-sqlite-options
487 :sqli-login sql-sqlite-login-params
488 :sqli-comint-func sql-comint-sqlite
490 :list-table
".schema %s"
491 :completion-object sql-sqlite-completion-object
492 :prompt-regexp
"^sqlite> "
494 :prompt-cont-regexp
"^ \\.\\.\\.> "
499 :font-lock sql-mode-sybase-font-lock-keywords
500 :sqli-program sql-sybase-program
501 :sqli-options sql-sybase-options
502 :sqli-login sql-sybase-login-params
503 :sqli-comint-func sql-comint-sybase
504 :prompt-regexp
"^SQL> "
506 :syntax-alist
((?
@ .
"_"))
507 :terminator
("^go" .
"go"))
511 :sqli-program sql-vertica-program
512 :sqli-options sql-vertica-options
513 :sqli-login sql-vertica-login-params
514 :sqli-comint-func sql-comint-vertica
515 :list-all
("\\d" .
"\\dS")
517 :prompt-regexp
"^\\w*=[#>] "
519 :prompt-cont-regexp
"^\\w*[-(][#>] ")
521 "An alist of product specific configuration settings.
523 Without an entry in this list a product will not be properly
524 highlighted and will not support `sql-interactive-mode'.
526 Each element in the list is in the following format:
528 (PRODUCT FEATURE VALUE ...)
530 where PRODUCT is the appropriate value of `sql-product'. The
531 product name is then followed by FEATURE-VALUE pairs. If a
532 FEATURE is not specified, its VALUE is treated as nil. FEATURE
533 may be any one of the following:
535 :name string containing the displayable name of
538 :free-software is the product Free (as in Freedom) software?
540 :font-lock name of the variable containing the product
541 specific font lock highlighting patterns.
543 :sqli-program name of the variable containing the product
544 specific interactive program name.
546 :sqli-options name of the variable containing the list
547 of product specific options.
549 :sqli-login name of the variable containing the list of
550 login parameters (i.e., user, password,
551 database and server) needed to connect to
554 :sqli-comint-func name of a function of two arguments, PRODUCT
555 and OPTIONS, that will open a comint buffer
556 and connect to the database. PRODUCT is the
557 first argument to be passed to `sql-comint',
558 and OPTIONS should be included in its second
559 argument. The function should use the values
560 of `sql-user', `sql-password', `sql-database',
561 `sql-server' and `sql-port' to . Do product
562 specific configuration of comint in this
563 function. See `sql-comint-oracle' for an
564 example of such a function.
566 :list-all Command string or function which produces
567 a listing of all objects in the database.
568 If it's a cons cell, then the car
569 produces the standard list of objects and
570 the cdr produces an enhanced list of
571 objects. What \"enhanced\" means is
572 dependent on the SQL product and may not
573 exist. In general though, the
574 \"enhanced\" list should include visible
575 objects from other schemas.
577 :list-table Command string or function which produces
578 a detailed listing of a specific database
579 table. If its a cons cell, then the car
580 produces the standard list and the cdr
581 produces an enhanced list.
583 :completion-object A function that returns a list of
584 objects. Called with a single
585 parameter--if nil then list objects
586 accessible in the current schema, if
587 not-nil it is the name of a schema whose
588 objects should be listed.
590 :completion-column A function that returns a list of
591 columns. Called with a single
592 parameter--if nil then list objects
593 accessible in the current schema, if
594 not-nil it is the name of a schema whose
595 objects should be listed.
597 :prompt-regexp regular expression string that matches
598 the prompt issued by the product
601 :prompt-length length of the prompt on the line.
603 :prompt-cont-regexp regular expression string that matches
604 the continuation prompt issued by the
607 :input-filter function which can filter strings sent to
608 the command interpreter. It is also used
609 by the `sql-send-string',
610 `sql-send-region', `sql-send-paragraph'
611 and `sql-send-buffer' functions. The
612 function is passed the string sent to the
613 command interpreter and must return the
614 filtered string. May also be a list of
617 :statement name of a variable containing a regexp that
618 matches the beginning of SQL statements.
620 :terminator the terminator to be sent after a
621 `sql-send-string', `sql-send-region',
622 `sql-send-paragraph' and
623 `sql-send-buffer' command. May be the
624 literal string or a cons of a regexp to
625 match an existing terminator in the
626 string and the terminator to be used if
627 its absent. By default \";\".
629 :syntax-alist alist of syntax table entries to enable
630 special character treatment by font-lock
633 Other features can be stored but they will be ignored. However,
634 you can develop new functionality which is product independent by
635 using `sql-get-product-feature' to lookup the product specific
638 (defvar sql-indirect-features
639 '(:font-lock
:sqli-program
:sqli-options
:sqli-login
:statement
))
641 (defcustom sql-connection-alist nil
642 "An alist of connection parameters for interacting with a SQL product.
643 Each element of the alist is as follows:
645 (CONNECTION \(SQL-VARIABLE VALUE) ...)
647 Where CONNECTION is a case-insensitive string identifying the
648 connection, SQL-VARIABLE is the symbol name of a SQL mode
649 variable, and VALUE is the value to be assigned to the variable.
650 The most common SQL-VARIABLE settings associated with a
651 connection are: `sql-product', `sql-user', `sql-password',
652 `sql-port', `sql-server', and `sql-database'.
654 If a SQL-VARIABLE is part of the connection, it will not be
655 prompted for during login. The command `sql-connect' starts a
656 predefined SQLi session using the parameters from this list.
657 Connections defined here appear in the submenu SQL->Start... for
658 making new SQLi sessions."
659 :type
`(alist :key-type
(string :tag
"Connection")
662 (group (const :tag
"Product" sql-product
)
667 ,(or (plist-get (cdr prod-info
) :name
)
669 (symbol-name (car prod-info
))))
670 (quote ,(car prod-info
))))
672 (group (const :tag
"Username" sql-user
) string
)
673 (group (const :tag
"Password" sql-password
) string
)
674 (group (const :tag
"Server" sql-server
) string
)
675 (group (const :tag
"Database" sql-database
) string
)
676 (group (const :tag
"Port" sql-port
) integer
)
679 (symbol :tag
" Variable Symbol")
680 (sexp :tag
"Value Expression")))))
684 (defcustom sql-product
'ansi
685 "Select the SQL database product used.
686 This allows highlighting buffers properly when you open them."
688 ,@(mapcar (lambda (prod-info)
690 ,(or (plist-get (cdr prod-info
) :name
)
691 (capitalize (symbol-name (car prod-info
))))
696 (defvaralias 'sql-dialect
'sql-product
)
698 ;; misc customization of sql.el behavior
700 (defcustom sql-electric-stuff nil
701 "Treat some input as electric.
702 If set to the symbol `semicolon', then hitting `;' will send current
703 input in the SQLi buffer to the process.
704 If set to the symbol `go', then hitting `go' on a line by itself will
705 send current input in the SQLi buffer to the process.
706 If set to nil, then you must use \\[comint-send-input] in order to send
707 current input in the SQLi buffer to the process."
708 :type
'(choice (const :tag
"Nothing" nil
)
709 (const :tag
"The semicolon `;'" semicolon
)
710 (const :tag
"The string `go' by itself" go
))
714 (defcustom sql-send-terminator nil
715 "When non-nil, add a terminator to text sent to the SQL interpreter.
717 When text is sent to the SQL interpreter (via `sql-send-string',
718 `sql-send-region', `sql-send-paragraph' or `sql-send-buffer'), a
719 command terminator can be automatically sent as well. The
720 terminator is not sent, if the string sent already ends with the
723 If this value is t, then the default command terminator for the
724 SQL interpreter is sent. If this value is a string, then the
727 If the value is a cons cell of the form (PAT . TERM), then PAT is
728 a regexp used to match the terminator in the string and TERM is
729 the terminator to be sent. This form is useful if the SQL
730 interpreter has more than one way of submitting a SQL command.
731 The PAT regexp can match any of them, and TERM is the way we do
734 :type
'(choice (const :tag
"No Terminator" nil
)
735 (const :tag
"Default Terminator" t
)
736 (string :tag
"Terminator String")
737 (cons :tag
"Terminator Pattern and String"
738 (string :tag
"Terminator Pattern")
739 (string :tag
"Terminator String")))
743 (defvar sql-contains-names nil
744 "When non-nil, the current buffer contains database names.
746 Globally should be set to nil; it will be non-nil in `sql-mode',
747 `sql-interactive-mode' and list all buffers.")
749 (defvar sql-login-delay
7.5 ;; Secs
750 "Maximum number of seconds you are willing to wait for a login connection.")
752 (defcustom sql-pop-to-buffer-after-send-region nil
753 "When non-nil, pop to the buffer SQL statements are sent to.
755 After a call to `sql-sent-string', `sql-send-region',
756 `sql-send-paragraph' or `sql-send-buffer', the window is split
757 and the SQLi buffer is shown. If this variable is not nil, that
758 buffer's window will be selected by calling `pop-to-buffer'. If
759 this variable is nil, that buffer is shown using
764 ;; imenu support for sql-mode.
766 (defvar sql-imenu-generic-expression
767 ;; Items are in reverse order because they are rendered in reverse.
768 '(("Rules/Defaults" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*\\(?:rule\\|default\\)\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\s-+\\(\\(?:\\w+\\s-*[.]\\s-*\\)*\\w+\\)" 1)
769 ("Sequences" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*sequence\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\(?:\\w+\\s-*[.]\\s-*\\)*\\w+\\)" 1)
770 ("Triggers" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*trigger\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\(?:\\w+\\s-*[.]\\s-*\\)*\\w+\\)" 1)
771 ("Functions" "^\\s-*\\(?:create\\s-+\\(?:\\w+\\s-+\\)*\\)?function\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\(?:\\w+\\s-*[.]\\s-*\\)*\\w+\\)" 1)
772 ("Procedures" "^\\s-*\\(?:create\\s-+\\(?:\\w+\\s-+\\)*\\)?proc\\(?:edure\\)?\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\(?:\\w+\\s-*[.]\\s-*\\)*\\w+\\)" 1)
773 ("Packages" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*package\\s-+\\(?:body\\s-+\\)?\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\(?:\\w+\\s-*[.]\\s-*\\)*\\w+\\)" 1)
774 ("Types" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*type\\s-+\\(?:body\\s-+\\)?\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\(?:\\w+\\s-*[.]\\s-*\\)*\\w+\\)" 1)
775 ("Indexes" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*index\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\(?:\\w+\\s-*[.]\\s-*\\)*\\w+\\)" 1)
776 ("Tables/Views" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*\\(?:table\\|view\\)\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\(?:\\w+\\s-*[.]\\s-*\\)*\\w+\\)" 1))
777 "Define interesting points in the SQL buffer for `imenu'.
779 This is used to set `imenu-generic-expression' when SQL mode is
780 entered. Subsequent changes to `sql-imenu-generic-expression' will
781 not affect existing SQL buffers because imenu-generic-expression is
786 (defcustom sql-input-ring-file-name nil
787 "If non-nil, name of the file to read/write input history.
789 You have to set this variable if you want the history of your commands
790 saved from one Emacs session to the next. If this variable is set,
791 exiting the SQL interpreter in an SQLi buffer will write the input
792 history to the specified file. Starting a new process in a SQLi buffer
793 will read the input history from the specified file.
795 This is used to initialize `comint-input-ring-file-name'.
797 Note that the size of the input history is determined by the variable
798 `comint-input-ring-size'."
799 :type
'(choice (const :tag
"none" nil
)
803 (defcustom sql-input-ring-separator
"\n--\n"
804 "Separator between commands in the history file.
806 If set to \"\\n\", each line in the history file will be interpreted as
807 one command. Multi-line commands are split into several commands when
808 the input ring is initialized from a history file.
810 This variable used to initialize `comint-input-ring-separator'.
811 `comint-input-ring-separator' is part of Emacs 21; if your Emacs
812 does not have it, setting `sql-input-ring-separator' will have no
813 effect. In that case multiline commands will be split into several
814 commands when the input history is read, as if you had set
815 `sql-input-ring-separator' to \"\\n\"."
821 (defcustom sql-interactive-mode-hook
'()
822 "Hook for customizing `sql-interactive-mode'."
826 (defcustom sql-mode-hook
'()
827 "Hook for customizing `sql-mode'."
831 (defcustom sql-set-sqli-hook
'()
832 "Hook for reacting to changes of `sql-buffer'.
834 This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
839 (defcustom sql-login-hook
'()
840 "Hook for interacting with a buffer in `sql-interactive-mode'.
842 This hook is invoked in a buffer once it is ready to accept input
848 ;; Customization for ANSI
850 (defcustom sql-ansi-statement-starters
851 (regexp-opt '("create" "alter" "drop"
852 "select" "insert" "update" "delete" "merge"
854 "Regexp of keywords that start SQL commands.
856 All products share this list; products should define a regexp to
857 identify additional keywords in a variable defined by
858 the :statement feature."
863 ;; Customization for Oracle
865 (defcustom sql-oracle-program
"sqlplus"
866 "Command to start sqlplus by Oracle.
868 Starts `sql-interactive-mode' after doing some setup.
870 On Windows, \"sqlplus\" usually starts the sqlplus \"GUI\". In order
871 to start the sqlplus console, use \"plus33\" or something similar.
872 You will find the file in your Orant\\bin directory."
876 (defcustom sql-oracle-options
'("-L")
877 "List of additional options for `sql-oracle-program'."
878 :type
'(repeat string
)
882 (defcustom sql-oracle-login-params
'(user password database
)
883 "List of login parameters needed to connect to Oracle."
884 :type
'sql-login-params
888 (defcustom sql-oracle-statement-starters
889 (regexp-opt '("declare" "begin" "with"))
890 "Additional statement starting keywords in Oracle."
895 (defcustom sql-oracle-scan-on t
896 "Non-nil if placeholders should be replaced in Oracle SQLi.
898 When non-nil, Emacs will scan text sent to sqlplus and prompt
899 for replacement text for & placeholders as sqlplus does. This
900 is needed on Windows where SQL*Plus output is buffered and the
901 prompts are not shown until after the text is entered.
903 You need to issue the following command in SQL*Plus to be safe:
907 In older versions of SQL*Plus, this was the SET SCAN OFF command."
912 (defcustom sql-db2-escape-newlines nil
913 "Non-nil if newlines should be escaped by a backslash in DB2 SQLi.
915 When non-nil, Emacs will automatically insert a space and
916 backslash prior to every newline in multi-line SQL statements as
917 they are submitted to an interactive DB2 session."
922 ;; Customization for SQLite
924 (defcustom sql-sqlite-program
(or (executable-find "sqlite3")
925 (executable-find "sqlite")
927 "Command to start SQLite.
929 Starts `sql-interactive-mode' after doing some setup."
933 (defcustom sql-sqlite-options nil
934 "List of additional options for `sql-sqlite-program'."
935 :type
'(repeat string
)
939 (defcustom sql-sqlite-login-params
'((database :file
".*\\.\\(db\\|sqlite[23]?\\)"))
940 "List of login parameters needed to connect to SQLite."
941 :type
'sql-login-params
945 ;; Customization for MySQL
947 (defcustom sql-mysql-program
"mysql"
948 "Command to start mysql by TcX.
950 Starts `sql-interactive-mode' after doing some setup."
954 (defcustom sql-mysql-options nil
955 "List of additional options for `sql-mysql-program'.
956 The following list of options is reported to make things work
957 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
958 :type
'(repeat string
)
962 (defcustom sql-mysql-login-params
'(user password database server
)
963 "List of login parameters needed to connect to MySQL."
964 :type
'sql-login-params
968 ;; Customization for Solid
970 (defcustom sql-solid-program
"solsql"
971 "Command to start SOLID SQL Editor.
973 Starts `sql-interactive-mode' after doing some setup."
977 (defcustom sql-solid-login-params
'(user password server
)
978 "List of login parameters needed to connect to Solid."
979 :type
'sql-login-params
983 ;; Customization for Sybase
985 (defcustom sql-sybase-program
"isql"
986 "Command to start isql by Sybase.
988 Starts `sql-interactive-mode' after doing some setup."
992 (defcustom sql-sybase-options nil
993 "List of additional options for `sql-sybase-program'.
994 Some versions of isql might require the -n option in order to work."
995 :type
'(repeat string
)
999 (defcustom sql-sybase-login-params
'(server user password database
)
1000 "List of login parameters needed to connect to Sybase."
1001 :type
'sql-login-params
1005 ;; Customization for Informix
1007 (defcustom sql-informix-program
"dbaccess"
1008 "Command to start dbaccess by Informix.
1010 Starts `sql-interactive-mode' after doing some setup."
1014 (defcustom sql-informix-login-params
'(database)
1015 "List of login parameters needed to connect to Informix."
1016 :type
'sql-login-params
1020 ;; Customization for Ingres
1022 (defcustom sql-ingres-program
"sql"
1023 "Command to start sql by Ingres.
1025 Starts `sql-interactive-mode' after doing some setup."
1029 (defcustom sql-ingres-login-params
'(database)
1030 "List of login parameters needed to connect to Ingres."
1031 :type
'sql-login-params
1035 ;; Customization for Microsoft
1037 (defcustom sql-ms-program
"osql"
1038 "Command to start osql by Microsoft.
1040 Starts `sql-interactive-mode' after doing some setup."
1044 (defcustom sql-ms-options
'("-w" "300" "-n")
1045 ;; -w is the linesize
1046 "List of additional options for `sql-ms-program'."
1047 :type
'(repeat string
)
1051 (defcustom sql-ms-login-params
'(user password server database
)
1052 "List of login parameters needed to connect to Microsoft."
1053 :type
'sql-login-params
1057 ;; Customization for Postgres
1059 (defcustom sql-postgres-program
"psql"
1060 "Command to start psql by Postgres.
1062 Starts `sql-interactive-mode' after doing some setup."
1066 (defcustom sql-postgres-options
'("-P" "pager=off")
1067 "List of additional options for `sql-postgres-program'.
1068 The default setting includes the -P option which breaks older versions
1069 of the psql client (such as version 6.5.3). The -P option is equivalent
1070 to the --pset option. If you want the psql to prompt you for a user
1071 name, add the string \"-u\" to the list of options. If you want to
1072 provide a user name on the command line (newer versions such as 7.1),
1073 add your name with a \"-U\" prefix (such as \"-Umark\") to the list."
1074 :type
'(repeat string
)
1078 (defcustom sql-postgres-login-params
`((user :default
,(user-login-name))
1079 (database :default
,(user-login-name))
1081 "List of login parameters needed to connect to Postgres."
1082 :type
'sql-login-params
1086 ;; Customization for Interbase
1088 (defcustom sql-interbase-program
"isql"
1089 "Command to start isql by Interbase.
1091 Starts `sql-interactive-mode' after doing some setup."
1095 (defcustom sql-interbase-options nil
1096 "List of additional options for `sql-interbase-program'."
1097 :type
'(repeat string
)
1101 (defcustom sql-interbase-login-params
'(user password database
)
1102 "List of login parameters needed to connect to Interbase."
1103 :type
'sql-login-params
1107 ;; Customization for DB2
1109 (defcustom sql-db2-program
"db2"
1110 "Command to start db2 by IBM.
1112 Starts `sql-interactive-mode' after doing some setup."
1116 (defcustom sql-db2-options nil
1117 "List of additional options for `sql-db2-program'."
1118 :type
'(repeat string
)
1122 (defcustom sql-db2-login-params nil
1123 "List of login parameters needed to connect to DB2."
1124 :type
'sql-login-params
1128 ;; Customization for Linter
1130 (defcustom sql-linter-program
"inl"
1131 "Command to start inl by RELEX.
1133 Starts `sql-interactive-mode' after doing some setup."
1137 (defcustom sql-linter-options nil
1138 "List of additional options for `sql-linter-program'."
1139 :type
'(repeat string
)
1143 (defcustom sql-linter-login-params
'(user password database server
)
1144 "Login parameters to needed to connect to Linter."
1145 :type
'sql-login-params
1151 ;;; Variables which do not need customization
1153 (defvar sql-user-history nil
1154 "History of usernames used.")
1156 (defvar sql-database-history nil
1157 "History of databases used.")
1159 (defvar sql-server-history nil
1160 "History of servers used.")
1162 ;; Passwords are not kept in a history.
1164 (defvar sql-product-history nil
1165 "History of products used.")
1167 (defvar sql-connection-history nil
1168 "History of connections used.")
1170 (defvar sql-buffer nil
1171 "Current SQLi buffer.
1173 The global value of `sql-buffer' is the name of the latest SQLi buffer
1174 created. Any SQL buffer created will make a local copy of this value.
1175 See `sql-interactive-mode' for more on multiple sessions. If you want
1176 to change the SQLi buffer a SQL mode sends its SQL strings to, change
1177 the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
1179 (defvar sql-prompt-regexp nil
1180 "Prompt used to initialize `comint-prompt-regexp'.
1182 You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.")
1184 (defvar sql-prompt-length
0
1185 "Prompt used to set `left-margin' in `sql-interactive-mode'.
1187 You can change `sql-prompt-length' on `sql-interactive-mode-hook'.")
1189 (defvar sql-prompt-cont-regexp nil
1190 "Prompt pattern of statement continuation prompts.")
1192 (defvar sql-alternate-buffer-name nil
1193 "Buffer-local string used to possibly rename the SQLi buffer.
1195 Used by `sql-rename-buffer'.")
1197 (defun sql-buffer-live-p (buffer &optional product connection
)
1198 "Return non-nil if the process associated with buffer is live.
1200 BUFFER can be a buffer object or a buffer name. The buffer must
1201 be a live buffer, have a running process attached to it, be in
1202 `sql-interactive-mode', and, if PRODUCT or CONNECTION are
1203 specified, it's `sql-product' or `sql-connection' must match."
1206 (setq buffer
(get-buffer buffer
))
1208 (buffer-live-p buffer
)
1209 (comint-check-proc buffer
)
1210 (with-current-buffer buffer
1211 (and (derived-mode-p 'sql-interactive-mode
)
1213 (eq product sql-product
))
1214 (or (not connection
)
1215 (eq connection sql-connection
)))))))
1217 ;; Keymap for sql-interactive-mode.
1219 (defvar sql-interactive-mode-map
1220 (let ((map (make-sparse-keymap)))
1221 (if (fboundp 'set-keymap-parent
)
1222 (set-keymap-parent map comint-mode-map
); Emacs
1223 (if (fboundp 'set-keymap-parents
)
1224 (set-keymap-parents map
(list comint-mode-map
)))); XEmacs
1225 (if (fboundp 'set-keymap-name
)
1226 (set-keymap-name map
'sql-interactive-mode-map
)); XEmacs
1227 (define-key map
(kbd "C-j") 'sql-accumulate-and-indent
)
1228 (define-key map
(kbd "C-c C-w") 'sql-copy-column
)
1229 (define-key map
(kbd "O") 'sql-magic-go
)
1230 (define-key map
(kbd "o") 'sql-magic-go
)
1231 (define-key map
(kbd ";") 'sql-magic-semicolon
)
1232 (define-key map
(kbd "C-c C-l a") 'sql-list-all
)
1233 (define-key map
(kbd "C-c C-l t") 'sql-list-table
)
1235 "Mode map used for `sql-interactive-mode'.
1236 Based on `comint-mode-map'.")
1238 ;; Keymap for sql-mode.
1240 (defvar sql-mode-map
1241 (let ((map (make-sparse-keymap)))
1242 (define-key map
(kbd "C-c C-c") 'sql-send-paragraph
)
1243 (define-key map
(kbd "C-c C-r") 'sql-send-region
)
1244 (define-key map
(kbd "C-c C-s") 'sql-send-string
)
1245 (define-key map
(kbd "C-c C-b") 'sql-send-buffer
)
1246 (define-key map
(kbd "C-c C-n") 'sql-send-line-and-next
)
1247 (define-key map
(kbd "C-c C-i") 'sql-product-interactive
)
1248 (define-key map
(kbd "C-c C-z") 'sql-show-sqli-buffer
)
1249 (define-key map
(kbd "C-c C-l a") 'sql-list-all
)
1250 (define-key map
(kbd "C-c C-l t") 'sql-list-table
)
1251 (define-key map
[remap beginning-of-defun
] 'sql-beginning-of-statement
)
1252 (define-key map
[remap end-of-defun
] 'sql-end-of-statement
)
1254 "Mode map used for `sql-mode'.")
1256 ;; easy menu for sql-mode.
1259 sql-mode-menu sql-mode-map
1260 "Menu for `sql-mode'."
1262 ["Send Paragraph" sql-send-paragraph
(sql-buffer-live-p sql-buffer
)]
1263 ["Send Region" sql-send-region
(and mark-active
1264 (sql-buffer-live-p sql-buffer
))]
1265 ["Send Buffer" sql-send-buffer
(sql-buffer-live-p sql-buffer
)]
1266 ["Send String" sql-send-string
(sql-buffer-live-p sql-buffer
)]
1268 ["List all objects" sql-list-all
(and (sql-buffer-live-p sql-buffer
)
1269 (sql-get-product-feature sql-product
:list-all
))]
1270 ["List table details" sql-list-table
(and (sql-buffer-live-p sql-buffer
)
1271 (sql-get-product-feature sql-product
:list-table
))]
1273 ["Start SQLi session" sql-product-interactive
1274 :visible
(not sql-connection-alist
)
1275 :enable
(sql-get-product-feature sql-product
:sqli-comint-func
)]
1277 :visible sql-connection-alist
1278 :filter sql-connection-menu-filter
1280 ["New SQLi Session" sql-product-interactive
(sql-get-product-feature sql-product
:sqli-comint-func
)])
1282 :visible sql-connection-alist
]
1283 ["Show SQLi buffer" sql-show-sqli-buffer t
]
1284 ["Set SQLi buffer" sql-set-sqli-buffer t
]
1285 ["Pop to SQLi buffer after send"
1286 sql-toggle-pop-to-buffer-after-send-region
1288 :selected sql-pop-to-buffer-after-send-region
]
1291 ,@(mapcar (lambda (prod-info)
1292 (let* ((prod (pop prod-info
))
1293 (name (or (plist-get prod-info
:name
)
1294 (capitalize (symbol-name prod
))))
1295 (cmd (intern (format "sql-highlight-%s-keywords" prod
))))
1296 (fset cmd
`(lambda () ,(format "Highlight %s SQL keywords." name
)
1298 (sql-set-product ',prod
)))
1301 :selected
`(eq sql-product
',prod
))))
1302 sql-product-alist
))))
1304 ;; easy menu for sql-interactive-mode.
1307 sql-interactive-mode-menu sql-interactive-mode-map
1308 "Menu for `sql-interactive-mode'."
1310 ["Rename Buffer" sql-rename-buffer t
]
1311 ["Save Connection" sql-save-connection
(not sql-connection
)]
1313 ["List all objects" sql-list-all
(sql-get-product-feature sql-product
:list-all
)]
1314 ["List table details" sql-list-table
(sql-get-product-feature sql-product
:list-table
)]))
1316 ;; Abbreviations -- if you want more of them, define them in your init
1317 ;; file. Abbrevs have to be enabled in your init file, too.
1319 (define-abbrev-table 'sql-mode-abbrev-table
1320 '(("ins" "insert" nil nil t
)
1321 ("upd" "update" nil nil t
)
1322 ("del" "delete" nil nil t
)
1323 ("sel" "select" nil nil t
)
1324 ("proc" "procedure" nil nil t
)
1325 ("func" "function" nil nil t
)
1326 ("cr" "create" nil nil t
))
1327 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")
1331 (defvar sql-mode-syntax-table
1332 (let ((table (make-syntax-table)))
1333 ;; C-style comments /**/ (see elisp manual "Syntax Flags"))
1334 (modify-syntax-entry ?
/ ". 14" table
)
1335 (modify-syntax-entry ?
* ". 23" table
)
1336 ;; double-dash starts comments
1337 (modify-syntax-entry ?-
". 12b" table
)
1338 ;; newline and formfeed end comments
1339 (modify-syntax-entry ?
\n "> b" table
)
1340 (modify-syntax-entry ?
\f "> b" table
)
1341 ;; single quotes (') delimit strings
1342 (modify-syntax-entry ?
' "\"" table
)
1343 ;; double quotes (") don't delimit strings
1344 (modify-syntax-entry ?
\" "." table
)
1345 ;; Make these all punctuation
1346 (mapc #'(lambda (c) (modify-syntax-entry c
"." table
))
1347 (string-to-list "!#$%&+,.:;<=>?@\\|"))
1349 "Syntax table used in `sql-mode' and `sql-interactive-mode'.")
1351 ;; Font lock support
1353 (defvar sql-mode-font-lock-object-name
1355 (list (concat "^\\s-*\\(?:create\\|drop\\|alter\\)\\s-+" ;; lead off with CREATE, DROP or ALTER
1356 "\\(?:\\w+\\s-+\\)*" ;; optional intervening keywords
1357 "\\(?:table\\|view\\|\\(?:package\\|type\\)\\(?:\\s-+body\\)?\\|proc\\(?:edure\\)?"
1358 "\\|function\\|trigger\\|sequence\\|rule\\|default\\)\\s-+"
1359 "\\(?:if\\s-+not\\s-+exists\\s-+\\)?" ;; IF NOT EXISTS
1360 "\\(\\w+\\(?:\\s-*[.]\\s-*\\w+\\)*\\)")
1361 1 'font-lock-function-name-face
))
1363 "Pattern to match the names of top-level objects.
1365 The pattern matches the name in a CREATE, DROP or ALTER
1366 statement. The format of variable should be a valid
1367 `font-lock-keywords' entry.")
1369 ;; While there are international and American standards for SQL, they
1370 ;; are not followed closely, and most vendors offer significant
1371 ;; capabilities beyond those defined in the standard specifications.
1373 ;; SQL mode provides support for highlighting based on the product. In
1374 ;; addition to highlighting the product keywords, any ANSI keywords not
1375 ;; used by the product are also highlighted. This will help identify
1376 ;; keywords that could be restricted in future versions of the product
1377 ;; or might be a problem if ported to another product.
1379 ;; To reduce the complexity and size of the regular expressions
1380 ;; generated to match keywords, ANSI keywords are filtered out of
1381 ;; product keywords if they are equivalent. To do this, we define a
1382 ;; function `sql-font-lock-keywords-builder' that removes any keywords
1383 ;; that are matched by the ANSI patterns and results in the same face
1384 ;; being applied. For this to work properly, we must play some games
1385 ;; with the execution and compile time behavior. This code is a
1386 ;; little tricky but works properly.
1388 ;; When defining the keywords for individual products you should
1389 ;; include all of the keywords that you want matched. The filtering
1390 ;; against the ANSI keywords will be automatic if you use the
1391 ;; `sql-font-lock-keywords-builder' function and follow the
1392 ;; implementation pattern used for the other products in this file.
1395 (defvar sql-mode-ansi-font-lock-keywords
)
1396 (setq sql-mode-ansi-font-lock-keywords nil
))
1399 (defun sql-font-lock-keywords-builder (face boundaries
&rest keywords
)
1400 "Generation of regexp matching any one of KEYWORDS."
1402 (let ((bdy (or boundaries
'("\\b" .
"\\b")))
1405 ;; Remove keywords that are defined in ANSI
1407 ;; (dolist (k keywords)
1409 ;; (dolist (a sql-mode-ansi-font-lock-keywords)
1410 ;; (when (and (eq face (cdr a))
1411 ;; (eq (string-match (car a) k 0) 0)
1412 ;; (eq (match-end 0) (length k)))
1413 ;; (setq kwd (delq k kwd))
1414 ;; (throw 'next nil)))))
1416 ;; Create a properly formed font-lock-keywords item
1417 (cons (concat (car bdy
)
1422 (defun sql-regexp-abbrev (keyword)
1423 (let ((brk (string-match "[~]" keyword
))
1424 (len (length keyword
))
1429 (setq re
(substring keyword
0 brk
)
1433 (setq re
(concat re sep
(substring keyword brk i
))
1436 (concat re
"\\)?"))))
1438 (defun sql-regexp-abbrev-list (&rest keyw-list
)
1442 (setq re
(concat re sep
(sql-regexp-abbrev (car keyw-list
)))
1444 keyw-list
(cdr keyw-list
)))
1445 (concat re
"\\)\\>"))))
1448 (setq sql-mode-ansi-font-lock-keywords
1450 ;; ANSI Non Reserved keywords
1451 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1452 "ada" "asensitive" "assignment" "asymmetric" "atomic" "between"
1453 "bitvar" "called" "catalog_name" "chain" "character_set_catalog"
1454 "character_set_name" "character_set_schema" "checked" "class_origin"
1455 "cobol" "collation_catalog" "collation_name" "collation_schema"
1456 "column_name" "command_function" "command_function_code" "committed"
1457 "condition_number" "connection_name" "constraint_catalog"
1458 "constraint_name" "constraint_schema" "contains" "cursor_name"
1459 "datetime_interval_code" "datetime_interval_precision" "defined"
1460 "definer" "dispatch" "dynamic_function" "dynamic_function_code"
1461 "existing" "exists" "final" "fortran" "generated" "granted"
1462 "hierarchy" "hold" "implementation" "infix" "insensitive" "instance"
1463 "instantiable" "invoker" "key_member" "key_type" "length" "m"
1464 "message_length" "message_octet_length" "message_text" "method" "more"
1465 "mumps" "name" "nullable" "number" "options" "overlaps" "overriding"
1466 "parameter_mode" "parameter_name" "parameter_ordinal_position"
1467 "parameter_specific_catalog" "parameter_specific_name"
1468 "parameter_specific_schema" "pascal" "pli" "position" "repeatable"
1469 "returned_length" "returned_octet_length" "returned_sqlstate"
1470 "routine_catalog" "routine_name" "routine_schema" "row_count" "scale"
1471 "schema_name" "security" "self" "sensitive" "serializable"
1472 "server_name" "similar" "simple" "source" "specific_name" "style"
1473 "subclass_origin" "sublist" "symmetric" "system" "table_name"
1474 "transaction_active" "transactions_committed"
1475 "transactions_rolled_back" "transform" "transforms" "trigger_catalog"
1476 "trigger_name" "trigger_schema" "type" "uncommitted" "unnamed"
1477 "user_defined_type_catalog" "user_defined_type_name"
1478 "user_defined_type_schema"
1481 ;; ANSI Reserved keywords
1482 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1483 "absolute" "action" "add" "admin" "after" "aggregate" "alias" "all"
1484 "allocate" "alter" "and" "any" "are" "as" "asc" "assertion" "at"
1485 "authorization" "before" "begin" "both" "breadth" "by" "call"
1486 "cascade" "cascaded" "case" "catalog" "check" "class" "close"
1487 "collate" "collation" "column" "commit" "completion" "connect"
1488 "connection" "constraint" "constraints" "constructor" "continue"
1489 "corresponding" "create" "cross" "cube" "current" "cursor" "cycle"
1490 "data" "day" "deallocate" "declare" "default" "deferrable" "deferred"
1491 "delete" "depth" "deref" "desc" "describe" "descriptor" "destroy"
1492 "destructor" "deterministic" "diagnostics" "dictionary" "disconnect"
1493 "distinct" "domain" "drop" "dynamic" "each" "else" "end" "equals"
1494 "escape" "every" "except" "exception" "exec" "execute" "external"
1495 "false" "fetch" "first" "for" "foreign" "found" "free" "from" "full"
1496 "function" "general" "get" "global" "go" "goto" "grant" "group"
1497 "grouping" "having" "host" "hour" "identity" "ignore" "immediate" "in"
1498 "indicator" "initialize" "initially" "inner" "inout" "input" "insert"
1499 "intersect" "into" "is" "isolation" "iterate" "join" "key" "language"
1500 "last" "lateral" "leading" "left" "less" "level" "like" "limit"
1501 "local" "locator" "map" "match" "minute" "modifies" "modify" "module"
1502 "month" "names" "natural" "new" "next" "no" "none" "not" "null" "of"
1503 "off" "old" "on" "only" "open" "operation" "option" "or" "order"
1504 "ordinality" "out" "outer" "output" "pad" "parameter" "parameters"
1505 "partial" "path" "postfix" "prefix" "preorder" "prepare" "preserve"
1506 "primary" "prior" "privileges" "procedure" "public" "read" "reads"
1507 "recursive" "references" "referencing" "relative" "restrict" "result"
1508 "return" "returns" "revoke" "right" "role" "rollback" "rollup"
1509 "routine" "rows" "savepoint" "schema" "scroll" "search" "second"
1510 "section" "select" "sequence" "session" "set" "sets" "size" "some"
1511 "space" "specific" "specifictype" "sql" "sqlexception" "sqlstate"
1512 "sqlwarning" "start" "state" "statement" "static" "structure" "table"
1513 "temporary" "terminate" "than" "then" "timezone_hour"
1514 "timezone_minute" "to" "trailing" "transaction" "translation"
1515 "trigger" "true" "under" "union" "unique" "unknown" "unnest" "update"
1516 "usage" "using" "value" "values" "variable" "view" "when" "whenever"
1517 "where" "with" "without" "work" "write" "year"
1521 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1522 "abs" "avg" "bit_length" "cardinality" "cast" "char_length"
1523 "character_length" "coalesce" "convert" "count" "current_date"
1524 "current_path" "current_role" "current_time" "current_timestamp"
1525 "current_user" "extract" "localtime" "localtimestamp" "lower" "max"
1526 "min" "mod" "nullif" "octet_length" "overlay" "placing" "session_user"
1527 "substring" "sum" "system_user" "translate" "treat" "trim" "upper"
1532 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1533 "array" "binary" "bit" "blob" "boolean" "char" "character" "clob"
1534 "date" "dec" "decimal" "double" "float" "int" "integer" "interval"
1535 "large" "national" "nchar" "nclob" "numeric" "object" "precision"
1536 "real" "ref" "row" "scope" "smallint" "time" "timestamp" "varchar"
1540 (defvar sql-mode-ansi-font-lock-keywords
1541 (eval-when-compile sql-mode-ansi-font-lock-keywords
)
1542 "ANSI SQL keywords used by font-lock.
1544 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1545 regular expressions are created during compilation by calling the
1546 function `regexp-opt'. Therefore, take a look at the source before
1547 you define your own `sql-mode-ansi-font-lock-keywords'. You may want
1548 to add functions and PL/SQL keywords.")
1550 (defun sql--oracle-show-reserved-words ()
1551 ;; This function is for use by the maintainer of SQL.EL only.
1552 (if (or (and (not (derived-mode-p 'sql-mode
))
1553 (not (derived-mode-p 'sql-interactive-mode
)))
1555 (not (eq sql-product
'oracle
)))
1556 (user-error "Not an Oracle buffer")
1558 (let ((b "*RESERVED WORDS*"))
1559 (sql-execute sql-buffer b
1562 ", reserved AS \"Res\" "
1563 ", res_type AS \"Type\" "
1564 ", res_attr AS \"Attr\" "
1565 ", res_semi AS \"Semi\" "
1566 ", duplicate AS \"Dup\" "
1567 "FROM V$RESERVED_WORDS "
1569 "AND SUBSTR(keyword, 1, 1) BETWEEN 'A' AND 'Z' "
1570 "ORDER BY 2 DESC, 3 DESC, 4 DESC, 5 DESC, 6 DESC, 1;")
1572 (with-current-buffer b
1573 (set (make-local-variable 'sql-product
) 'oracle
)
1574 (sql-product-font-lock t nil
)
1575 (font-lock-mode +1)))))
1577 (defvar sql-mode-oracle-font-lock-keywords
1580 ;; Oracle SQL*Plus Commands
1581 ;; Only recognized in they start in column 1 and the
1582 ;; abbreviation is followed by a space or the end of line.
1583 (list (concat "^" (sql-regexp-abbrev "rem~ark") "\\(?:\\s-.*\\)?$")
1584 0 'font-lock-comment-face t
)
1589 (sql-regexp-abbrev-list
1590 "[@]\\{1,2\\}" "acc~ept" "a~ppend" "archive" "attribute"
1591 "bre~ak" "bti~tle" "c~hange" "cl~ear" "col~umn" "conn~ect"
1592 "copy" "def~ine" "del" "desc~ribe" "disc~onnect" "ed~it"
1593 "exec~ute" "exit" "get" "help" "ho~st" "[$]" "i~nput" "l~ist"
1594 "passw~ord" "pau~se" "pri~nt" "pro~mpt" "quit" "recover"
1595 "repf~ooter" "reph~eader" "r~un" "sav~e" "sho~w" "shutdown"
1596 "spo~ol" "sta~rt" "startup" "store" "tim~ing" "tti~tle"
1597 "undef~ine" "var~iable" "whenever")
1600 (sql-regexp-abbrev "comp~ute")
1602 (sql-regexp-abbrev-list
1603 "avg" "cou~nt" "min~imum" "max~imum" "num~ber" "sum"
1607 (concat "\\(?:set\\s-+"
1608 (sql-regexp-abbrev-list
1609 "appi~nfo" "array~size" "auto~commit" "autop~rint"
1610 "autorecovery" "autot~race" "blo~ckterminator"
1611 "cmds~ep" "colsep" "com~patibility" "con~cat"
1612 "copyc~ommit" "copytypecheck" "def~ine" "describe"
1613 "echo" "editf~ile" "emb~edded" "esc~ape" "feed~back"
1614 "flagger" "flu~sh" "hea~ding" "heads~ep" "instance"
1615 "lin~esize" "lobof~fset" "long" "longc~hunksize"
1616 "mark~up" "newp~age" "null" "numf~ormat" "num~width"
1617 "pages~ize" "pau~se" "recsep" "recsepchar"
1618 "scan" "serverout~put" "shift~inout" "show~mode"
1619 "sqlbl~anklines" "sqlc~ase" "sqlco~ntinue"
1620 "sqln~umber" "sqlpluscompat~ibility" "sqlpre~fix"
1621 "sqlp~rompt" "sqlt~erminator" "suf~fix" "tab"
1622 "term~out" "ti~me" "timi~ng" "trim~out" "trims~pool"
1623 "und~erline" "ver~ify" "wra~p")
1626 "\\)\\(?:\\s-.*\\)?\\(?:[-]\n.*\\)*$")
1627 0 'font-lock-doc-face t
)
1628 '("&?&\\(?:\\sw\\|\\s_\\)+[.]?" 0 font-lock-preprocessor-face t
)
1630 ;; Oracle PL/SQL Attributes (Declare these first to match %TYPE correctly)
1631 (sql-font-lock-keywords-builder 'font-lock-builtin-face
'("%" .
"\\b")
1632 "bulk_exceptions" "bulk_rowcount" "found" "isopen" "notfound"
1633 "rowcount" "rowtype" "type"
1636 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1637 "abs" "acos" "add_months" "appendchildxml" "ascii" "asciistr" "asin"
1638 "atan" "atan2" "avg" "bfilename" "bin_to_num" "bitand" "cardinality"
1639 "cast" "ceil" "chartorowid" "chr" "cluster_id" "cluster_probability"
1640 "cluster_set" "coalesce" "collect" "compose" "concat" "convert" "corr"
1641 "connect_by_root" "connect_by_iscycle" "connect_by_isleaf"
1642 "corr_k" "corr_s" "cos" "cosh" "count" "covar_pop" "covar_samp"
1643 "cube_table" "cume_dist" "current_date" "current_timestamp" "cv"
1644 "dataobj_to_partition" "dbtimezone" "decode" "decompose" "deletexml"
1645 "dense_rank" "depth" "deref" "dump" "empty_blob" "empty_clob"
1646 "existsnode" "exp" "extract" "extractvalue" "feature_id" "feature_set"
1647 "feature_value" "first" "first_value" "floor" "from_tz" "greatest"
1648 "grouping" "grouping_id" "group_id" "hextoraw" "initcap"
1649 "insertchildxml" "insertchildxmlafter" "insertchildxmlbefore"
1650 "insertxmlafter" "insertxmlbefore" "instr" "instr2" "instr4" "instrb"
1651 "instrc" "iteration_number" "lag" "last" "last_day" "last_value"
1652 "lead" "least" "length" "length2" "length4" "lengthb" "lengthc"
1653 "listagg" "ln" "lnnvl" "localtimestamp" "log" "lower" "lpad" "ltrim"
1654 "make_ref" "max" "median" "min" "mod" "months_between" "nanvl" "nchr"
1655 "new_time" "next_day" "nlssort" "nls_charset_decl_len"
1656 "nls_charset_id" "nls_charset_name" "nls_initcap" "nls_lower"
1657 "nls_upper" "nth_value" "ntile" "nullif" "numtodsinterval"
1658 "numtoyminterval" "nvl" "nvl2" "ora_dst_affected" "ora_dst_convert"
1659 "ora_dst_error" "ora_hash" "path" "percentile_cont" "percentile_disc"
1660 "percent_rank" "power" "powermultiset" "powermultiset_by_cardinality"
1661 "prediction" "prediction_bounds" "prediction_cost"
1662 "prediction_details" "prediction_probability" "prediction_set"
1663 "presentnnv" "presentv" "previous" "rank" "ratio_to_report" "rawtohex"
1664 "rawtonhex" "ref" "reftohex" "regexp_count" "regexp_instr" "regexp_like"
1665 "regexp_replace" "regexp_substr" "regr_avgx" "regr_avgy" "regr_count"
1666 "regr_intercept" "regr_r2" "regr_slope" "regr_sxx" "regr_sxy"
1667 "regr_syy" "remainder" "replace" "round" "rowidtochar" "rowidtonchar"
1668 "row_number" "rpad" "rtrim" "scn_to_timestamp" "sessiontimezone" "set"
1669 "sign" "sin" "sinh" "soundex" "sqrt" "stats_binomial_test"
1670 "stats_crosstab" "stats_f_test" "stats_ks_test" "stats_mode"
1671 "stats_mw_test" "stats_one_way_anova" "stats_t_test_indep"
1672 "stats_t_test_indepu" "stats_t_test_one" "stats_t_test_paired"
1673 "stats_wsr_test" "stddev" "stddev_pop" "stddev_samp" "substr"
1674 "substr2" "substr4" "substrb" "substrc" "sum" "sysdate" "systimestamp"
1675 "sys_connect_by_path" "sys_context" "sys_dburigen" "sys_extract_utc"
1676 "sys_guid" "sys_typeid" "sys_xmlagg" "sys_xmlgen" "tan" "tanh"
1677 "timestamp_to_scn" "to_binary_double" "to_binary_float" "to_blob"
1678 "to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte"
1679 "to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp"
1680 "to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc"
1681 "tz_offset" "uid" "unistr" "updatexml" "upper" "user" "userenv"
1682 "value" "variance" "var_pop" "var_samp" "vsize" "width_bucket"
1683 "xmlagg" "xmlcast" "xmlcdata" "xmlcolattval" "xmlcomment" "xmlconcat"
1684 "xmldiff" "xmlelement" "xmlexists" "xmlforest" "xmlisvalid" "xmlparse"
1685 "xmlpatch" "xmlpi" "xmlquery" "xmlroot" "xmlsequence" "xmlserialize"
1686 "xmltable" "xmltransform"
1689 ;; See the table V$RESERVED_WORDS
1691 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1692 "abort" "access" "accessed" "account" "activate" "add" "admin"
1693 "advise" "after" "agent" "aggregate" "all" "allocate" "allow" "alter"
1694 "always" "analyze" "ancillary" "and" "any" "apply" "archive"
1695 "archivelog" "array" "as" "asc" "associate" "at" "attribute"
1696 "attributes" "audit" "authenticated" "authid" "authorization" "auto"
1697 "autoallocate" "automatic" "availability" "backup" "before" "begin"
1698 "behalf" "between" "binding" "bitmap" "block" "blocksize" "body"
1699 "both" "buffer_pool" "build" "by" "cache" "call" "cancel"
1700 "cascade" "case" "category" "certificate" "chained" "change" "check"
1701 "checkpoint" "child" "chunk" "class" "clear" "clone" "close" "cluster"
1702 "column" "column_value" "columns" "comment" "commit" "committed"
1703 "compatibility" "compile" "complete" "composite_limit" "compress"
1704 "compute" "connect" "connect_time" "consider" "consistent"
1705 "constraint" "constraints" "constructor" "contents" "context"
1706 "continue" "controlfile" "corruption" "cost" "cpu_per_call"
1707 "cpu_per_session" "create" "cross" "cube" "current" "currval" "cycle"
1708 "dangling" "data" "database" "datafile" "datafiles" "day" "ddl"
1709 "deallocate" "debug" "default" "deferrable" "deferred" "definer"
1710 "delay" "delete" "demand" "desc" "determines" "deterministic"
1711 "dictionary" "dimension" "directory" "disable" "disassociate"
1712 "disconnect" "distinct" "distinguished" "distributed" "dml" "drop"
1713 "each" "element" "else" "enable" "end" "equals_path" "escape"
1714 "estimate" "except" "exceptions" "exchange" "excluding" "exists"
1715 "expire" "explain" "extent" "external" "externally"
1716 "failed_login_attempts" "fast" "file" "final" "finish" "flush" "for"
1717 "force" "foreign" "freelist" "freelists" "freepools" "fresh" "from"
1718 "full" "function" "functions" "generated" "global" "global_name"
1719 "globally" "grant" "group" "grouping" "groups" "guard" "hash"
1720 "hashkeys" "having" "heap" "hierarchy" "id" "identified" "identifier"
1721 "idle_time" "immediate" "in" "including" "increment" "index" "indexed"
1722 "indexes" "indextype" "indextypes" "indicator" "initial" "initialized"
1723 "initially" "initrans" "inner" "insert" "instance" "instantiable"
1724 "instead" "intersect" "into" "invalidate" "is" "isolation" "java"
1725 "join" "keep" "key" "kill" "language" "left" "less" "level"
1726 "levels" "library" "like" "like2" "like4" "likec" "limit" "link"
1727 "list" "lob" "local" "location" "locator" "lock" "log" "logfile"
1728 "logging" "logical" "logical_reads_per_call"
1729 "logical_reads_per_session" "managed" "management" "manual" "map"
1730 "mapping" "master" "matched" "materialized" "maxdatafiles"
1731 "maxextents" "maximize" "maxinstances" "maxlogfiles" "maxloghistory"
1732 "maxlogmembers" "maxsize" "maxtrans" "maxvalue" "member" "memory"
1733 "merge" "migrate" "minextents" "minimize" "minimum" "minus" "minvalue"
1734 "mode" "modify" "monitoring" "month" "mount" "move" "movement" "name"
1735 "named" "natural" "nested" "never" "new" "next" "nextval" "no"
1736 "noarchivelog" "noaudit" "nocache" "nocompress" "nocopy" "nocycle"
1737 "nodelay" "noforce" "nologging" "nomapping" "nomaxvalue" "nominimize"
1738 "nominvalue" "nomonitoring" "none" "noorder" "noparallel" "norely"
1739 "noresetlogs" "noreverse" "normal" "norowdependencies" "nosort"
1740 "noswitch" "not" "nothing" "notimeout" "novalidate" "nowait" "null"
1741 "nulls" "object" "of" "off" "offline" "oidindex" "old" "on" "online"
1742 "only" "open" "operator" "optimal" "option" "or" "order"
1743 "organization" "out" "outer" "outline" "over" "overflow" "overriding"
1744 "package" "packages" "parallel" "parallel_enable" "parameters"
1745 "parent" "partition" "partitions" "password" "password_grace_time"
1746 "password_life_time" "password_lock_time" "password_reuse_max"
1747 "password_reuse_time" "password_verify_function" "pctfree"
1748 "pctincrease" "pctthreshold" "pctused" "pctversion" "percent"
1749 "performance" "permanent" "pfile" "physical" "pipelined" "pivot" "plan"
1750 "post_transaction" "pragma" "prebuilt" "preserve" "primary" "private"
1751 "private_sga" "privileges" "procedure" "profile" "protection" "public"
1752 "purge" "query" "quiesce" "quota" "range" "read" "reads" "rebuild"
1753 "records_per_block" "recover" "recovery" "recycle" "reduced" "ref"
1754 "references" "referencing" "refresh" "register" "reject" "relational"
1755 "rely" "rename" "reset" "resetlogs" "resize" "resolve" "resolver"
1756 "resource" "restrict" "restrict_references" "restricted" "result"
1757 "resumable" "resume" "retention" "return" "returning" "reuse"
1758 "reverse" "revoke" "rewrite" "right" "rnds" "rnps" "role" "roles"
1759 "rollback" "rollup" "row" "rowdependencies" "rownum" "rows" "sample"
1760 "savepoint" "scan" "schema" "scn" "scope" "segment" "select"
1761 "selectivity" "self" "sequence" "serializable" "session"
1762 "sessions_per_user" "set" "sets" "settings" "shared" "shared_pool"
1763 "shrink" "shutdown" "siblings" "sid" "single" "size" "skip" "some"
1764 "sort" "source" "space" "specification" "spfile" "split" "standby"
1765 "start" "statement_id" "static" "statistics" "stop" "storage" "store"
1766 "structure" "subpartition" "subpartitions" "substitutable"
1767 "successful" "supplemental" "suspend" "switch" "switchover" "synonym"
1768 "sys" "system" "table" "tables" "tablespace" "tempfile" "template"
1769 "temporary" "test" "than" "then" "thread" "through" "time_zone"
1770 "timeout" "to" "trace" "transaction" "trigger" "triggers" "truncate"
1771 "trust" "type" "types" "unarchived" "under" "under_path" "undo"
1772 "uniform" "union" "unique" "unlimited" "unlock" "unpivot" "unquiesce"
1773 "unrecoverable" "until" "unusable" "unused" "update" "upgrade" "usage"
1774 "use" "using" "validate" "validation" "value" "values" "variable"
1775 "varray" "version" "view" "wait" "when" "whenever" "where" "with"
1776 "without" "wnds" "wnps" "work" "write" "xmldata" "xmlschema" "xmltype"
1779 ;; Oracle Data Types
1780 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1781 "bfile" "binary_double" "binary_float" "blob" "byte" "char" "charbyte"
1782 "clob" "date" "day" "float" "interval" "local" "long" "longraw"
1783 "minute" "month" "nchar" "nclob" "number" "nvarchar2" "raw" "rowid" "second"
1784 "time" "timestamp" "urowid" "varchar2" "with" "year" "zone"
1787 ;; Oracle PL/SQL Functions
1788 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1789 "delete" "trim" "extend" "exists" "first" "last" "count" "limit"
1790 "prior" "next" "sqlcode" "sqlerrm"
1793 ;; Oracle PL/SQL Reserved words
1794 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1795 "all" "alter" "and" "any" "as" "asc" "at" "begin" "between" "by"
1796 "case" "check" "clusters" "cluster" "colauth" "columns" "compress"
1797 "connect" "crash" "create" "cursor" "declare" "default" "desc"
1798 "distinct" "drop" "else" "end" "exception" "exclusive" "fetch" "for"
1799 "from" "function" "goto" "grant" "group" "having" "identified" "if"
1800 "in" "index" "indexes" "insert" "intersect" "into" "is" "like" "lock"
1801 "minus" "mode" "nocompress" "not" "nowait" "null" "of" "on" "option"
1802 "or" "order" "overlaps" "procedure" "public" "resource" "revoke"
1803 "select" "share" "size" "sql" "start" "subtype" "tabauth" "table"
1804 "then" "to" "type" "union" "unique" "update" "values" "view" "views"
1805 "when" "where" "with"
1808 "raise_application_error"
1811 ;; Oracle PL/SQL Keywords
1812 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1813 "a" "add" "agent" "aggregate" "array" "attribute" "authid" "avg"
1814 "bfile_base" "binary" "blob_base" "block" "body" "both" "bound" "bulk"
1815 "byte" "c" "call" "calling" "cascade" "char" "char_base" "character"
1816 "charset" "charsetform" "charsetid" "clob_base" "close" "collect"
1817 "comment" "commit" "committed" "compiled" "constant" "constructor"
1818 "context" "continue" "convert" "count" "current" "customdatum"
1819 "dangling" "data" "date" "date_base" "day" "define" "delete"
1820 "deterministic" "double" "duration" "element" "elsif" "empty" "escape"
1821 "except" "exceptions" "execute" "exists" "exit" "external" "final"
1822 "fixed" "float" "forall" "force" "general" "hash" "heap" "hidden"
1823 "hour" "immediate" "including" "indicator" "indices" "infinite"
1824 "instantiable" "int" "interface" "interval" "invalidate" "isolation"
1825 "java" "language" "large" "leading" "length" "level" "library" "like2"
1826 "like4" "likec" "limit" "limited" "local" "long" "loop" "map" "max"
1827 "maxlen" "member" "merge" "min" "minute" "mod" "modify" "month"
1828 "multiset" "name" "nan" "national" "native" "nchar" "new" "nocopy"
1829 "number_base" "object" "ocicoll" "ocidate" "ocidatetime" "ociduration"
1830 "ociinterval" "ociloblocator" "ocinumber" "ociraw" "ociref"
1831 "ocirefcursor" "ocirowid" "ocistring" "ocitype" "old" "only" "opaque"
1832 "open" "operator" "oracle" "oradata" "organization" "orlany" "orlvary"
1833 "others" "out" "overriding" "package" "parallel_enable" "parameter"
1834 "parameters" "parent" "partition" "pascal" "pipe" "pipelined" "pragma"
1835 "precision" "prior" "private" "raise" "range" "raw" "read" "record"
1836 "ref" "reference" "relies_on" "rem" "remainder" "rename" "result"
1837 "result_cache" "return" "returning" "reverse" "rollback" "row"
1838 "sample" "save" "savepoint" "sb1" "sb2" "sb4" "second" "segment"
1839 "self" "separate" "sequence" "serializable" "set" "short" "size_t"
1840 "some" "sparse" "sqlcode" "sqldata" "sqlname" "sqlstate" "standard"
1841 "static" "stddev" "stored" "string" "struct" "style" "submultiset"
1842 "subpartition" "substitutable" "sum" "synonym" "tdo" "the" "time"
1843 "timestamp" "timezone_abbr" "timezone_hour" "timezone_minute"
1844 "timezone_region" "trailing" "transaction" "transactional" "trusted"
1845 "ub1" "ub2" "ub4" "under" "unsigned" "untrusted" "use" "using"
1846 "valist" "value" "variable" "variance" "varray" "varying" "void"
1847 "while" "work" "wrapped" "write" "year" "zone"
1849 "autonomous_transaction" "exception_init" "inline"
1850 "restrict_references" "serially_reusable"
1853 ;; Oracle PL/SQL Data Types
1854 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1855 "\"BINARY LARGE OBJECT\"" "\"CHAR LARGE OBJECT\"" "\"CHAR VARYING\""
1856 "\"CHARACTER LARGE OBJECT\"" "\"CHARACTER VARYING\""
1857 "\"DOUBLE PRECISION\"" "\"INTERVAL DAY TO SECOND\""
1858 "\"INTERVAL YEAR TO MONTH\"" "\"LONG RAW\"" "\"NATIONAL CHAR\""
1859 "\"NATIONAL CHARACTER LARGE OBJECT\"" "\"NATIONAL CHARACTER\""
1860 "\"NCHAR LARGE OBJECT\"" "\"NCHAR\"" "\"NCLOB\"" "\"NVARCHAR2\""
1861 "\"TIME WITH TIME ZONE\"" "\"TIMESTAMP WITH LOCAL TIME ZONE\""
1862 "\"TIMESTAMP WITH TIME ZONE\""
1863 "bfile" "bfile_base" "binary_double" "binary_float" "binary_integer"
1864 "blob" "blob_base" "boolean" "char" "character" "char_base" "clob"
1865 "clob_base" "cursor" "date" "day" "dec" "decimal"
1866 "dsinterval_unconstrained" "float" "int" "integer" "interval" "local"
1867 "long" "mlslabel" "month" "natural" "naturaln" "nchar_cs" "number"
1868 "number_base" "numeric" "pls_integer" "positive" "positiven" "raw"
1869 "real" "ref" "rowid" "second" "signtype" "simple_double"
1870 "simple_float" "simple_integer" "smallint" "string" "time" "timestamp"
1871 "timestamp_ltz_unconstrained" "timestamp_tz_unconstrained"
1872 "timestamp_unconstrained" "time_tz_unconstrained" "time_unconstrained"
1873 "to" "urowid" "varchar" "varchar2" "with" "year"
1874 "yminterval_unconstrained" "zone"
1877 ;; Oracle PL/SQL Exceptions
1878 (sql-font-lock-keywords-builder 'font-lock-warning-face nil
1879 "access_into_null" "case_not_found" "collection_is_null"
1880 "cursor_already_open" "dup_val_on_index" "invalid_cursor"
1881 "invalid_number" "login_denied" "no_data_found" "no_data_needed"
1882 "not_logged_on" "program_error" "rowtype_mismatch" "self_is_null"
1883 "storage_error" "subscript_beyond_count" "subscript_outside_limit"
1884 "sys_invalid_rowid" "timeout_on_resource" "too_many_rows"
1885 "value_error" "zero_divide"
1888 "Oracle SQL keywords used by font-lock.
1890 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1891 regular expressions are created during compilation by calling the
1892 function `regexp-opt'. Therefore, take a look at the source before
1893 you define your own `sql-mode-oracle-font-lock-keywords'. You may want
1894 to add functions and PL/SQL keywords.")
1896 (defvar sql-mode-postgres-font-lock-keywords
1899 ;; Postgres psql commands
1900 '("^\\s-*\\\\.*$" . font-lock-doc-face
)
1902 ;; Postgres unreserved words but may have meaning
1903 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
"a"
1904 "abs" "absent" "according" "ada" "alias" "allocate" "are" "array_agg"
1905 "asensitive" "atomic" "attribute" "attributes" "avg" "base64"
1906 "bernoulli" "bit_length" "bitvar" "blob" "blocked" "bom" "breadth" "c"
1907 "call" "cardinality" "catalog_name" "ceil" "ceiling" "char_length"
1908 "character_length" "character_set_catalog" "character_set_name"
1909 "character_set_schema" "characters" "checked" "class_origin" "clob"
1910 "cobol" "collation" "collation_catalog" "collation_name"
1911 "collation_schema" "collect" "column_name" "columns"
1912 "command_function" "command_function_code" "completion" "condition"
1913 "condition_number" "connect" "connection_name" "constraint_catalog"
1914 "constraint_name" "constraint_schema" "constructor" "contains"
1915 "control" "convert" "corr" "corresponding" "count" "covar_pop"
1916 "covar_samp" "cube" "cume_dist" "current_default_transform_group"
1917 "current_path" "current_transform_group_for_type" "cursor_name"
1918 "datalink" "datetime_interval_code" "datetime_interval_precision" "db"
1919 "defined" "degree" "dense_rank" "depth" "deref" "derived" "describe"
1920 "descriptor" "destroy" "destructor" "deterministic" "diagnostics"
1921 "disconnect" "dispatch" "dlnewcopy" "dlpreviouscopy" "dlurlcomplete"
1922 "dlurlcompleteonly" "dlurlcompletewrite" "dlurlpath" "dlurlpathonly"
1923 "dlurlpathwrite" "dlurlscheme" "dlurlserver" "dlvalue" "dynamic"
1924 "dynamic_function" "dynamic_function_code" "element" "empty"
1925 "end-exec" "equals" "every" "exception" "exec" "existing" "exp" "file"
1926 "filter" "final" "first_value" "flag" "floor" "fortran" "found" "free"
1927 "fs" "fusion" "g" "general" "generated" "get" "go" "goto" "grouping"
1928 "hex" "hierarchy" "host" "id" "ignore" "implementation" "import"
1929 "indent" "indicator" "infix" "initialize" "instance" "instantiable"
1930 "integrity" "intersection" "iterate" "k" "key_member" "key_type" "lag"
1931 "last_value" "lateral" "lead" "length" "less" "library" "like_regex"
1932 "link" "ln" "locator" "lower" "m" "map" "matched" "max"
1933 "max_cardinality" "member" "merge" "message_length"
1934 "message_octet_length" "message_text" "method" "min" "mod" "modifies"
1935 "modify" "module" "more" "multiset" "mumps" "namespace" "nclob"
1936 "nesting" "new" "nfc" "nfd" "nfkc" "nfkd" "nil" "normalize"
1937 "normalized" "nth_value" "ntile" "nullable" "number"
1938 "occurrences_regex" "octet_length" "octets" "old" "open" "operation"
1939 "ordering" "ordinality" "others" "output" "overriding" "p" "pad"
1940 "parameter" "parameter_mode" "parameter_name"
1941 "parameter_ordinal_position" "parameter_specific_catalog"
1942 "parameter_specific_name" "parameter_specific_schema" "parameters"
1943 "pascal" "passing" "passthrough" "percent_rank" "percentile_cont"
1944 "percentile_disc" "permission" "pli" "position_regex" "postfix"
1945 "power" "prefix" "preorder" "public" "rank" "reads" "recovery" "ref"
1946 "referencing" "regr_avgx" "regr_avgy" "regr_count" "regr_intercept"
1947 "regr_r2" "regr_slope" "regr_sxx" "regr_sxy" "regr_syy" "requiring"
1948 "respect" "restore" "result" "return" "returned_cardinality"
1949 "returned_length" "returned_octet_length" "returned_sqlstate" "rollup"
1950 "routine" "routine_catalog" "routine_name" "routine_schema"
1951 "row_count" "row_number" "scale" "schema_name" "scope" "scope_catalog"
1952 "scope_name" "scope_schema" "section" "selective" "self" "sensitive"
1953 "server_name" "sets" "size" "source" "space" "specific"
1954 "specific_name" "specifictype" "sql" "sqlcode" "sqlerror"
1955 "sqlexception" "sqlstate" "sqlwarning" "sqrt" "state" "static"
1956 "stddev_pop" "stddev_samp" "structure" "style" "subclass_origin"
1957 "sublist" "submultiset" "substring_regex" "sum" "system_user" "t"
1958 "table_name" "tablesample" "terminate" "than" "ties" "timezone_hour"
1959 "timezone_minute" "token" "top_level_count" "transaction_active"
1960 "transactions_committed" "transactions_rolled_back" "transform"
1961 "transforms" "translate" "translate_regex" "translation"
1962 "trigger_catalog" "trigger_name" "trigger_schema" "trim_array"
1963 "uescape" "under" "unlink" "unnamed" "unnest" "untyped" "upper" "uri"
1964 "usage" "user_defined_type_catalog" "user_defined_type_code"
1965 "user_defined_type_name" "user_defined_type_schema" "var_pop"
1966 "var_samp" "varbinary" "variable" "whenever" "width_bucket" "within"
1967 "xmlagg" "xmlbinary" "xmlcast" "xmlcomment" "xmldeclaration"
1968 "xmldocument" "xmlexists" "xmliterate" "xmlnamespaces" "xmlquery"
1969 "xmlschema" "xmltable" "xmltext" "xmlvalidate"
1972 ;; Postgres non-reserved words
1973 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1974 "abort" "absolute" "access" "action" "add" "admin" "after" "aggregate"
1975 "also" "alter" "always" "assertion" "assignment" "at" "attribute" "backward"
1976 "before" "begin" "between" "by" "cache" "called" "cascade" "cascaded"
1977 "catalog" "chain" "characteristics" "checkpoint" "class" "close"
1978 "cluster" "coalesce" "comment" "comments" "commit" "committed"
1979 "configuration" "connection" "constraints" "content" "continue"
1980 "conversion" "copy" "cost" "createdb" "createrole" "createuser" "csv"
1981 "current" "cursor" "cycle" "data" "database" "day" "deallocate" "dec"
1982 "declare" "defaults" "deferred" "definer" "delete" "delimiter"
1983 "delimiters" "dictionary" "disable" "discard" "document" "domain"
1984 "drop" "each" "enable" "encoding" "encrypted" "enum" "escape"
1985 "exclude" "excluding" "exclusive" "execute" "exists" "explain"
1986 "extension" "external" "extract" "family" "first" "float" "following" "force"
1987 "forward" "function" "functions" "global" "granted" "greatest"
1988 "handler" "header" "hold" "hour" "identity" "if" "immediate"
1989 "immutable" "implicit" "including" "increment" "index" "indexes"
1990 "inherit" "inherits" "inline" "inout" "input" "insensitive" "insert"
1991 "instead" "invoker" "isolation" "key" "label" "language" "large" "last"
1992 "lc_collate" "lc_ctype" "leakproof" "least" "level" "listen" "load" "local"
1993 "location" "lock" "login" "mapping" "match" "maxvalue" "minute"
1994 "minvalue" "mode" "month" "move" "names" "national" "nchar"
1995 "next" "no" "nocreatedb" "nocreaterole" "nocreateuser" "noinherit"
1996 "nologin" "none" "noreplication" "nosuperuser" "nothing" "notify" "nowait" "nullif"
1997 "nulls" "object" "of" "off" "oids" "operator" "option" "options" "out"
1998 "overlay" "owned" "owner" "parser" "partial" "partition" "passing" "password"
1999 "plans" "position" "preceding" "precision" "prepare" "prepared" "preserve" "prior"
2000 "privileges" "procedural" "procedure" "quote" "range" "read"
2001 "reassign" "recheck" "recursive" "ref" "reindex" "relative" "release"
2002 "rename" "repeatable" "replace" "replica" "replication" "reset" "restart" "restrict"
2003 "returns" "revoke" "role" "rollback" "row" "rows" "rule" "savepoint"
2004 "schema" "scroll" "search" "second" "security" "sequence"
2005 "serializable" "server" "session" "set" "setof" "share" "show"
2006 "simple" "snapshot" "stable" "standalone" "start" "statement" "statistics"
2007 "stdin" "stdout" "storage" "strict" "strip" "substring" "superuser"
2008 "sysid" "system" "tables" "tablespace" "temp" "template" "temporary"
2009 "transaction" "treat" "trim" "truncate" "trusted" "type" "types"
2010 "unbounded" "uncommitted" "unencrypted" "unlisten" "unlogged" "until"
2011 "update" "vacuum" "valid" "validate" "validator" "value" "values" "varying" "version"
2012 "view" "volatile" "whitespace" "without" "work" "wrapper" "write"
2013 "xmlattributes" "xmlconcat" "xmlelement" "xmlexists" "xmlforest" "xmlparse"
2014 "xmlpi" "xmlroot" "xmlserialize" "year" "yes" "zone"
2017 ;; Postgres Reserved
2018 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2019 "all" "analyse" "analyze" "and" "array" "asc" "as" "asymmetric"
2020 "authorization" "binary" "both" "case" "cast" "check" "collate"
2021 "column" "concurrently" "constraint" "create" "cross"
2022 "current_catalog" "current_date" "current_role" "current_schema"
2023 "current_time" "current_timestamp" "current_user" "default"
2024 "deferrable" "desc" "distinct" "do" "else" "end" "except" "false"
2025 "fetch" "foreign" "for" "freeze" "from" "full" "grant" "group"
2026 "having" "ilike" "initially" "inner" "in" "intersect" "into" "isnull"
2027 "is" "join" "leading" "left" "like" "limit" "localtime"
2028 "localtimestamp" "natural" "notnull" "not" "null" "offset"
2029 "only" "on" "order" "or" "outer" "overlaps" "over" "placing" "primary"
2030 "references" "returning" "right" "select" "session_user" "similar"
2031 "some" "symmetric" "table" "then" "to" "trailing" "true" "union"
2032 "unique" "user" "using" "variadic" "verbose" "when" "where" "window"
2036 ;; Postgres PL/pgSQL
2037 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2038 "assign" "if" "case" "loop" "while" "for" "foreach" "exit" "elsif" "return"
2039 "raise" "execsql" "dynexecute" "perform" "getdiag" "open" "fetch" "move" "close"
2042 ;; Postgres Data Types
2043 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2044 "bigint" "bigserial" "bit" "bool" "boolean" "box" "bytea" "char"
2045 "character" "cidr" "circle" "date" "decimal" "double" "float4"
2046 "float8" "inet" "int" "int2" "int4" "int8" "integer" "interval" "line"
2047 "lseg" "macaddr" "money" "name" "numeric" "path" "point" "polygon"
2048 "precision" "real" "serial" "serial4" "serial8" "sequences" "smallint" "text"
2049 "time" "timestamp" "timestamptz" "timetz" "tsquery" "tsvector"
2050 "txid_snapshot" "unknown" "uuid" "varbit" "varchar" "varying" "without"
2054 "Postgres SQL keywords used by font-lock.
2056 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2057 regular expressions are created during compilation by calling the
2058 function `regexp-opt'. Therefore, take a look at the source before
2059 you define your own `sql-mode-postgres-font-lock-keywords'.")
2061 (defvar sql-mode-linter-font-lock-keywords
2065 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2066 "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel"
2067 "committed" "count" "countblob" "cross" "current" "data" "database"
2068 "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred"
2069 "denied" "description" "device" "difference" "directory" "error"
2070 "escape" "euc" "exclusive" "external" "extfile" "false" "file"
2071 "filename" "filesize" "filetime" "filter" "findblob" "first" "foreign"
2072 "full" "fuzzy" "global" "granted" "ignore" "immediate" "increment"
2073 "indexes" "indexfile" "indexfiles" "indextime" "initial" "integrity"
2074 "internal" "key" "last_autoinc" "last_rowid" "limit" "linter"
2075 "linter_file_device" "linter_file_size" "linter_name_length" "ln"
2076 "local" "login" "maxisn" "maxrow" "maxrowid" "maxvalue" "message"
2077 "minvalue" "module" "names" "national" "natural" "new" "new_table"
2078 "no" "node" "noneuc" "nulliferror" "numbers" "off" "old" "old_table"
2079 "only" "operation" "optimistic" "option" "page" "partially" "password"
2080 "phrase" "plan" "precision" "primary" "priority" "privileges"
2081 "proc_info_size" "proc_par_name_len" "protocol" "quant" "range" "raw"
2082 "read" "record" "records" "references" "remote" "rename" "replication"
2083 "restart" "rewrite" "root" "row" "rule" "savepoint" "security"
2084 "sensitive" "sequence" "serializable" "server" "since" "size" "some"
2085 "startup" "statement" "station" "success" "sys_guid" "tables" "test"
2086 "timeout" "trace" "transaction" "translation" "trigger"
2087 "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown"
2088 "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes"
2089 "wait" "windows_code" "workspace" "write" "xml"
2093 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2094 "access" "action" "add" "address" "after" "all" "alter" "always" "and"
2095 "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit"
2096 "aud_obj_name_len" "backup" "base" "before" "between" "blobfile"
2097 "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check"
2098 "clear" "close" "column" "comment" "commit" "connect" "contains"
2099 "correct" "create" "delete" "desc" "disable" "disconnect" "distinct"
2100 "drop" "each" "ef" "else" "enable" "end" "event" "except" "exclude"
2101 "execute" "exists" "extract" "fetch" "finish" "for" "from" "get"
2102 "grant" "group" "having" "identified" "in" "index" "inner" "insert"
2103 "instead" "intersect" "into" "is" "isolation" "join" "left" "level"
2104 "like" "lock" "mode" "modify" "not" "nowait" "null" "of" "on" "open"
2105 "or" "order" "outer" "owner" "press" "prior" "procedure" "public"
2106 "purge" "rebuild" "resource" "restrict" "revoke" "right" "role"
2107 "rollback" "rownum" "select" "session" "set" "share" "shutdown"
2108 "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then"
2109 "to" "union" "unique" "unlock" "until" "update" "using" "values"
2110 "view" "when" "where" "with" "without"
2114 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
2115 "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime"
2116 "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw"
2117 "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log"
2118 "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl"
2119 "octet_length" "power" "rand" "rawtohex" "repeat_string"
2120 "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex"
2121 "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date"
2122 "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode"
2123 "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap"
2124 "instr" "least" "multime" "replace" "width"
2127 ;; Linter Data Types
2128 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2129 "bigint" "bitmap" "blob" "boolean" "char" "character" "date"
2130 "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar"
2131 "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte"
2135 "Linter SQL keywords used by font-lock.
2137 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2138 regular expressions are created during compilation by calling the
2139 function `regexp-opt'.")
2141 (defvar sql-mode-ms-font-lock-keywords
2144 ;; MS isql/osql Commands
2147 "^\\(?:\\(?:set\\s-+\\(?:"
2149 "datefirst" "dateformat" "deadlock_priority" "lock_timeout"
2150 "concat_null_yields_null" "cursor_close_on_commit"
2151 "disable_def_cnst_chk" "fips_flagger" "identity_insert" "language"
2152 "offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly"
2153 "nocount" "noexec" "numeric_roundabort" "parseonly"
2154 "query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults"
2155 "ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding"
2156 "ansi_warnings" "forceplan" "showplan_all" "showplan_text"
2157 "statistics" "implicit_transactions" "remote_proc_transactions"
2158 "transaction" "xact_abort"
2160 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$")
2161 'font-lock-doc-face
)
2164 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2165 "absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization"
2166 "avg" "backup" "begin" "between" "break" "browse" "bulk" "by"
2167 "cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce"
2168 "column" "commit" "committed" "compute" "confirm" "constraint"
2169 "contains" "containstable" "continue" "controlrow" "convert" "count"
2170 "create" "cross" "current" "current_date" "current_time"
2171 "current_timestamp" "current_user" "database" "deallocate" "declare"
2172 "default" "delete" "deny" "desc" "disk" "distinct" "distributed"
2173 "double" "drop" "dummy" "dump" "else" "end" "errlvl" "errorexit"
2174 "escape" "except" "exec" "execute" "exists" "exit" "fetch" "file"
2175 "fillfactor" "first" "floppy" "for" "foreign" "freetext"
2176 "freetexttable" "from" "full" "goto" "grant" "group" "having"
2177 "holdlock" "identity" "identity_insert" "identitycol" "if" "in"
2178 "index" "inner" "insert" "intersect" "into" "is" "isolation" "join"
2179 "key" "kill" "last" "left" "level" "like" "lineno" "load" "max" "min"
2180 "mirrorexit" "national" "next" "nocheck" "nolock" "nonclustered" "not"
2181 "null" "nullif" "of" "off" "offsets" "on" "once" "only" "open"
2182 "opendatasource" "openquery" "openrowset" "option" "or" "order"
2183 "outer" "output" "over" "paglock" "percent" "perm" "permanent" "pipe"
2184 "plan" "precision" "prepare" "primary" "print" "prior" "privileges"
2185 "proc" "procedure" "processexit" "public" "raiserror" "read"
2186 "readcommitted" "readpast" "readtext" "readuncommitted" "reconfigure"
2187 "references" "relative" "repeatable" "repeatableread" "replication"
2188 "restore" "restrict" "return" "revoke" "right" "rollback" "rowcount"
2189 "rowguidcol" "rowlock" "rule" "save" "schema" "select" "serializable"
2190 "session_user" "set" "shutdown" "some" "statistics" "sum"
2191 "system_user" "table" "tablock" "tablockx" "tape" "temp" "temporary"
2192 "textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate"
2193 "tsequal" "uncommitted" "union" "unique" "update" "updatetext"
2194 "updlock" "use" "user" "values" "view" "waitfor" "when" "where"
2195 "while" "with" "work" "writetext" "collate" "function" "openxml"
2200 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
2201 "@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts"
2202 "@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy"
2203 "@@langid" "@@language" "@@lock_timeout" "@@max_connections"
2204 "@@max_precision" "@@nestlevel" "@@options" "@@pack_received"
2205 "@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount"
2206 "@@servername" "@@servicename" "@@spid" "@@textsize" "@@timeticks"
2207 "@@total_errors" "@@total_read" "@@total_write" "@@trancount"
2208 "@@version" "abs" "acos" "and" "app_name" "ascii" "asin" "atan" "atn2"
2209 "avg" "case" "cast" "ceiling" "char" "charindex" "coalesce"
2210 "col_length" "col_name" "columnproperty" "containstable" "convert"
2211 "cos" "cot" "count" "current_timestamp" "current_user" "cursor_status"
2212 "databaseproperty" "datalength" "dateadd" "datediff" "datename"
2213 "datepart" "day" "db_id" "db_name" "degrees" "difference" "exp"
2214 "file_id" "file_name" "filegroup_id" "filegroup_name"
2215 "filegroupproperty" "fileproperty" "floor" "formatmessage"
2216 "freetexttable" "fulltextcatalogproperty" "fulltextserviceproperty"
2217 "getansinull" "getdate" "grouping" "host_id" "host_name" "ident_incr"
2218 "ident_seed" "identity" "index_col" "indexproperty" "is_member"
2219 "is_srvrolemember" "isdate" "isnull" "isnumeric" "left" "len" "log"
2220 "log10" "lower" "ltrim" "max" "min" "month" "nchar" "newid" "nullif"
2221 "object_id" "object_name" "objectproperty" "openquery" "openrowset"
2222 "parsename" "patindex" "patindex" "permissions" "pi" "power"
2223 "quotename" "radians" "rand" "replace" "replicate" "reverse" "right"
2224 "round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt"
2225 "square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum"
2226 "suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan"
2227 "textptr" "textvalid" "typeproperty" "unicode" "upper" "user"
2228 "user_id" "user_name" "var" "varp" "year"
2232 '("\\b@[a-zA-Z0-9_]*\\b" . font-lock-variable-name-face
)
2235 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2236 "binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal"
2237 "double" "float" "image" "int" "integer" "money" "national" "nchar"
2238 "ntext" "numeric" "numeric" "nvarchar" "precision" "real"
2239 "smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint"
2240 "uniqueidentifier" "varbinary" "varchar" "varying"
2243 "Microsoft SQLServer SQL keywords used by font-lock.
2245 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2246 regular expressions are created during compilation by calling the
2247 function `regexp-opt'. Therefore, take a look at the source before
2248 you define your own `sql-mode-ms-font-lock-keywords'.")
2250 (defvar sql-mode-sybase-font-lock-keywords nil
2251 "Sybase SQL keywords used by font-lock.
2253 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2254 regular expressions are created during compilation by calling the
2255 function `regexp-opt'. Therefore, take a look at the source before
2256 you define your own `sql-mode-sybase-font-lock-keywords'.")
2258 (defvar sql-mode-informix-font-lock-keywords nil
2259 "Informix SQL keywords used by font-lock.
2261 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2262 regular expressions are created during compilation by calling the
2263 function `regexp-opt'. Therefore, take a look at the source before
2264 you define your own `sql-mode-informix-font-lock-keywords'.")
2266 (defvar sql-mode-interbase-font-lock-keywords nil
2267 "Interbase SQL keywords used by font-lock.
2269 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2270 regular expressions are created during compilation by calling the
2271 function `regexp-opt'. Therefore, take a look at the source before
2272 you define your own `sql-mode-interbase-font-lock-keywords'.")
2274 (defvar sql-mode-ingres-font-lock-keywords nil
2275 "Ingres SQL keywords used by font-lock.
2277 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2278 regular expressions are created during compilation by calling the
2279 function `regexp-opt'. Therefore, take a look at the source before
2280 you define your own `sql-mode-interbase-font-lock-keywords'.")
2282 (defvar sql-mode-solid-font-lock-keywords nil
2283 "Solid SQL keywords used by font-lock.
2285 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2286 regular expressions are created during compilation by calling the
2287 function `regexp-opt'. Therefore, take a look at the source before
2288 you define your own `sql-mode-solid-font-lock-keywords'.")
2290 (defvar sql-mode-mysql-font-lock-keywords
2294 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
2295 "ascii" "avg" "bdmpolyfromtext" "bdmpolyfromwkb" "bdpolyfromtext"
2296 "bdpolyfromwkb" "benchmark" "bin" "bit_and" "bit_length" "bit_or"
2297 "bit_xor" "both" "cast" "char_length" "character_length" "coalesce"
2298 "concat" "concat_ws" "connection_id" "conv" "convert" "count"
2299 "curdate" "current_date" "current_time" "current_timestamp" "curtime"
2300 "elt" "encrypt" "export_set" "field" "find_in_set" "found_rows" "from"
2301 "geomcollfromtext" "geomcollfromwkb" "geometrycollectionfromtext"
2302 "geometrycollectionfromwkb" "geometryfromtext" "geometryfromwkb"
2303 "geomfromtext" "geomfromwkb" "get_lock" "group_concat" "hex" "ifnull"
2304 "instr" "interval" "isnull" "last_insert_id" "lcase" "leading"
2305 "length" "linefromtext" "linefromwkb" "linestringfromtext"
2306 "linestringfromwkb" "load_file" "locate" "lower" "lpad" "ltrim"
2307 "make_set" "master_pos_wait" "max" "mid" "min" "mlinefromtext"
2308 "mlinefromwkb" "mpointfromtext" "mpointfromwkb" "mpolyfromtext"
2309 "mpolyfromwkb" "multilinestringfromtext" "multilinestringfromwkb"
2310 "multipointfromtext" "multipointfromwkb" "multipolygonfromtext"
2311 "multipolygonfromwkb" "now" "nullif" "oct" "octet_length" "ord"
2312 "pointfromtext" "pointfromwkb" "polyfromtext" "polyfromwkb"
2313 "polygonfromtext" "polygonfromwkb" "position" "quote" "rand"
2314 "release_lock" "repeat" "replace" "reverse" "rpad" "rtrim" "soundex"
2315 "space" "std" "stddev" "substring" "substring_index" "sum" "sysdate"
2316 "trailing" "trim" "ucase" "unix_timestamp" "upper" "user" "variance"
2320 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2321 "action" "add" "after" "against" "all" "alter" "and" "as" "asc"
2322 "auto_increment" "avg_row_length" "bdb" "between" "by" "cascade"
2323 "case" "change" "character" "check" "checksum" "close" "collate"
2324 "collation" "column" "columns" "comment" "committed" "concurrent"
2325 "constraint" "create" "cross" "data" "database" "default"
2326 "delay_key_write" "delayed" "delete" "desc" "directory" "disable"
2327 "distinct" "distinctrow" "do" "drop" "dumpfile" "duplicate" "else" "elseif"
2328 "enable" "enclosed" "end" "escaped" "exists" "fields" "first" "for"
2329 "force" "foreign" "from" "full" "fulltext" "global" "group" "handler"
2330 "having" "heap" "high_priority" "if" "ignore" "in" "index" "infile"
2331 "inner" "insert" "insert_method" "into" "is" "isam" "isolation" "join"
2332 "key" "keys" "last" "left" "level" "like" "limit" "lines" "load"
2333 "local" "lock" "low_priority" "match" "max_rows" "merge" "min_rows"
2334 "mode" "modify" "mrg_myisam" "myisam" "natural" "next" "no" "not"
2335 "null" "offset" "oj" "on" "open" "optionally" "or" "order" "outer"
2336 "outfile" "pack_keys" "partial" "password" "prev" "primary"
2337 "procedure" "quick" "raid0" "raid_type" "read" "references" "rename"
2338 "repeatable" "restrict" "right" "rollback" "rollup" "row_format"
2339 "savepoint" "select" "separator" "serializable" "session" "set"
2340 "share" "show" "sql_big_result" "sql_buffer_result" "sql_cache"
2341 "sql_calc_found_rows" "sql_no_cache" "sql_small_result" "starting"
2342 "straight_join" "striped" "table" "tables" "temporary" "terminated"
2343 "then" "to" "transaction" "truncate" "type" "uncommitted" "union"
2344 "unique" "unlock" "update" "use" "using" "values" "when" "where"
2345 "with" "write" "xor"
2349 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2350 "bigint" "binary" "bit" "blob" "bool" "boolean" "char" "curve" "date"
2351 "datetime" "dec" "decimal" "double" "enum" "fixed" "float" "geometry"
2352 "geometrycollection" "int" "integer" "line" "linearring" "linestring"
2353 "longblob" "longtext" "mediumblob" "mediumint" "mediumtext"
2354 "multicurve" "multilinestring" "multipoint" "multipolygon"
2355 "multisurface" "national" "numeric" "point" "polygon" "precision"
2356 "real" "smallint" "surface" "text" "time" "timestamp" "tinyblob"
2357 "tinyint" "tinytext" "unsigned" "varchar" "year" "year2" "year4"
2361 "MySQL SQL keywords used by font-lock.
2363 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2364 regular expressions are created during compilation by calling the
2365 function `regexp-opt'. Therefore, take a look at the source before
2366 you define your own `sql-mode-mysql-font-lock-keywords'.")
2368 (defvar sql-mode-sqlite-font-lock-keywords
2372 '("^[.].*$" . font-lock-doc-face
)
2375 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2376 "abort" "action" "add" "after" "all" "alter" "analyze" "and" "as"
2377 "asc" "attach" "autoincrement" "before" "begin" "between" "by"
2378 "cascade" "case" "cast" "check" "collate" "column" "commit" "conflict"
2379 "constraint" "create" "cross" "database" "default" "deferrable"
2380 "deferred" "delete" "desc" "detach" "distinct" "drop" "each" "else"
2381 "end" "escape" "except" "exclusive" "exists" "explain" "fail" "for"
2382 "foreign" "from" "full" "glob" "group" "having" "if" "ignore"
2383 "immediate" "in" "index" "indexed" "initially" "inner" "insert"
2384 "instead" "intersect" "into" "is" "isnull" "join" "key" "left" "like"
2385 "limit" "match" "natural" "no" "not" "notnull" "null" "of" "offset"
2386 "on" "or" "order" "outer" "plan" "pragma" "primary" "query" "raise"
2387 "references" "regexp" "reindex" "release" "rename" "replace"
2388 "restrict" "right" "rollback" "row" "savepoint" "select" "set" "table"
2389 "temp" "temporary" "then" "to" "transaction" "trigger" "union"
2390 "unique" "update" "using" "vacuum" "values" "view" "virtual" "when"
2393 ;; SQLite Data types
2394 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2395 "int" "integer" "tinyint" "smallint" "mediumint" "bigint" "unsigned"
2396 "big" "int2" "int8" "character" "varchar" "varying" "nchar" "native"
2397 "nvarchar" "text" "clob" "blob" "real" "double" "precision" "float"
2398 "numeric" "number" "decimal" "boolean" "date" "datetime"
2401 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
2403 "abs" "changes" "coalesce" "glob" "ifnull" "hex" "last_insert_rowid"
2404 "length" "like" "load_extension" "lower" "ltrim" "max" "min" "nullif"
2405 "quote" "random" "randomblob" "replace" "round" "rtrim" "soundex"
2406 "sqlite_compileoption_get" "sqlite_compileoption_used"
2407 "sqlite_source_id" "sqlite_version" "substr" "total_changes" "trim"
2408 "typeof" "upper" "zeroblob"
2409 ;; Date/time functions
2410 "time" "julianday" "strftime"
2411 "current_date" "current_time" "current_timestamp"
2412 ;; Aggregate functions
2413 "avg" "count" "group_concat" "max" "min" "sum" "total"
2416 "SQLite SQL keywords used by font-lock.
2418 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2419 regular expressions are created during compilation by calling the
2420 function `regexp-opt'. Therefore, take a look at the source before
2421 you define your own `sql-mode-sqlite-font-lock-keywords'.")
2423 (defvar sql-mode-db2-font-lock-keywords nil
2424 "DB2 SQL keywords used by font-lock.
2426 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2427 regular expressions are created during compilation by calling the
2428 function `regexp-opt'. Therefore, take a look at the source before
2429 you define your own `sql-mode-db2-font-lock-keywords'.")
2431 (defvar sql-mode-font-lock-keywords nil
2432 "SQL keywords used by font-lock.
2434 Setting this variable directly no longer has any affect. Use
2435 `sql-product' and `sql-add-product-keywords' to control the
2436 highlighting rules in SQL mode.")
2440 ;;; SQL Product support functions
2442 (defun sql-read-product (prompt &optional initial
)
2443 "Read a valid SQL product."
2444 (let ((init (or (and initial
(symbol-name initial
)) "ansi")))
2445 (intern (completing-read
2447 (mapcar #'(lambda (info) (symbol-name (car info
)))
2450 init
'sql-product-history init
))))
2452 (defun sql-add-product (product display
&rest plist
)
2453 "Add support for a database product in `sql-mode'.
2455 Add PRODUCT to `sql-product-alist' which enables `sql-mode' to
2456 properly support syntax highlighting and interactive interaction.
2457 DISPLAY is the name of the SQL product that will appear in the
2458 menu bar and in messages. PLIST initializes the product
2461 ;; Don't do anything if the product is already supported
2462 (if (assoc product sql-product-alist
)
2463 (user-error "Product `%s' is already defined" product
)
2465 ;; Add product to the alist
2466 (add-to-list 'sql-product-alist
`(,product
:name
,display .
,plist
))
2467 ;; Add a menu item to the SQL->Product menu
2468 (easy-menu-add-item sql-mode-menu
'("Product")
2469 ;; Each product is represented by a radio
2470 ;; button with it's display name.
2472 (sql-set-product ',product
)
2474 :selected
(eq sql-product
',product
)]
2475 ;; Maintain the product list in
2476 ;; (case-insensitive) alphabetic order of the
2477 ;; display names. Loop thru each keymap item
2478 ;; looking for an item whose display name is
2479 ;; after this product's name.
2481 (down-display (downcase display
)))
2482 (map-keymap #'(lambda (k b
)
2483 (when (and (not next-item
)
2484 (string-lessp down-display
2485 (downcase (cadr b
))))
2486 (setq next-item k
)))
2487 (easy-menu-get-map sql-mode-menu
'("Product")))
2491 (defun sql-del-product (product)
2492 "Remove support for PRODUCT in `sql-mode'."
2494 ;; Remove the menu item based on the display name
2495 (easy-menu-remove-item sql-mode-menu
'("Product") (sql-get-product-feature product
:name
))
2496 ;; Remove the product alist item
2497 (setq sql-product-alist
(assq-delete-all product sql-product-alist
))
2500 (defun sql-set-product-feature (product feature newvalue
)
2501 "Set FEATURE of database PRODUCT to NEWVALUE.
2503 The PRODUCT must be a symbol which identifies the database
2504 product. The product must have already exist on the product
2505 list. See `sql-add-product' to add new products. The FEATURE
2506 argument must be a plist keyword accepted by
2507 `sql-product-alist'."
2509 (let* ((p (assoc product sql-product-alist
))
2510 (v (plist-get (cdr p
) feature
)))
2513 (member feature sql-indirect-features
)
2516 (setcdr p
(plist-put (cdr p
) feature newvalue
)))
2517 (error "`%s' is not a known product; use `sql-add-product' to add it first." product
))))
2519 (defun sql-get-product-feature (product feature
&optional fallback not-indirect
)
2520 "Lookup FEATURE associated with a SQL PRODUCT.
2522 If the FEATURE is nil for PRODUCT, and FALLBACK is specified,
2523 then the FEATURE associated with the FALLBACK product is
2526 If the FEATURE is in the list `sql-indirect-features', and the
2527 NOT-INDIRECT parameter is not set, then the value of the symbol
2528 stored in the connect alist is returned.
2530 See `sql-product-alist' for a list of products and supported features."
2531 (let* ((p (assoc product sql-product-alist
))
2532 (v (plist-get (cdr p
) feature
)))
2535 ;; If no value and fallback, lookup feature for fallback
2538 (not (eq product fallback
)))
2539 (sql-get-product-feature fallback feature
)
2542 (member feature sql-indirect-features
)
2547 (error "`%s' is not a known product; use `sql-add-product' to add it first." product
)
2550 (defun sql-product-font-lock (keywords-only imenu
)
2551 "Configure font-lock and imenu with product-specific settings.
2553 The KEYWORDS-ONLY flag is passed to font-lock to specify whether
2554 only keywords should be highlighted and syntactic highlighting
2555 skipped. The IMENU flag indicates whether `imenu-mode' should
2556 also be configured."
2559 ;; Get the product-specific syntax-alist.
2560 ((syntax-alist (sql-product-font-lock-syntax-alist)))
2562 ;; Get the product-specific keywords.
2563 (set (make-local-variable 'sql-mode-font-lock-keywords
)
2565 (unless (eq sql-product
'ansi
)
2566 (sql-get-product-feature sql-product
:font-lock
))
2567 ;; Always highlight ANSI keywords
2568 (sql-get-product-feature 'ansi
:font-lock
)
2569 ;; Fontify object names in CREATE, DROP and ALTER DDL
2571 (list sql-mode-font-lock-object-name
)))
2573 ;; Setup font-lock. Force re-parsing of `font-lock-defaults'.
2574 (kill-local-variable 'font-lock-set-defaults
)
2575 (set (make-local-variable 'font-lock-defaults
)
2576 (list 'sql-mode-font-lock-keywords
2577 keywords-only t syntax-alist
))
2579 ;; Force font lock to reinitialize if it is already on
2580 ;; Otherwise, we can wait until it can be started.
2581 (when (and (fboundp 'font-lock-mode
)
2582 (boundp 'font-lock-mode
)
2584 (font-lock-mode-internal nil
)
2585 (font-lock-mode-internal t
))
2587 (add-hook 'font-lock-mode-hook
2589 ;; Provide defaults for new font-lock faces.
2590 (defvar font-lock-builtin-face
2591 (if (boundp 'font-lock-preprocessor-face
)
2592 font-lock-preprocessor-face
2593 font-lock-keyword-face
))
2594 (defvar font-lock-doc-face font-lock-string-face
))
2597 ;; Setup imenu; it needs the same syntax-alist.
2599 (setq imenu-syntax-alist syntax-alist
))))
2602 (defun sql-add-product-keywords (product keywords
&optional append
)
2603 "Add highlighting KEYWORDS for SQL PRODUCT.
2605 PRODUCT should be a symbol, the name of a SQL product, such as
2606 `oracle'. KEYWORDS should be a list; see the variable
2607 `font-lock-keywords'. By default they are added at the beginning
2608 of the current highlighting list. If optional argument APPEND is
2609 `set', they are used to replace the current highlighting list.
2610 If APPEND is any other non-nil value, they are added at the end
2611 of the current highlighting list.
2615 (sql-add-product-keywords \\='ms
2616 \\='((\"\\\\b\\\\w+_t\\\\b\" . font-lock-type-face)))
2618 adds a fontification pattern to fontify identifiers ending in
2619 `_t' as data types."
2621 (let* ((sql-indirect-features nil
)
2622 (font-lock-var (sql-get-product-feature product
:font-lock
))
2625 (setq old-val
(symbol-value font-lock-var
))
2627 (if (eq append
'set
)
2630 (append old-val keywords
)
2631 (append keywords old-val
))))))
2633 (defun sql-for-each-login (login-params body
)
2634 "Iterate through login parameters and return a list of results."
2638 (let ((token (or (car-safe param
) param
))
2639 (plist (cdr-safe param
)))
2640 (funcall body token plist
)))
2645 ;;; Functions to switch highlighting
2647 (defun sql-product-syntax-table ()
2648 (let ((table (copy-syntax-table sql-mode-syntax-table
)))
2649 (mapc #'(lambda (entry)
2650 (modify-syntax-entry (car entry
) (cdr entry
) table
))
2651 (sql-get-product-feature sql-product
:syntax-alist
))
2654 (defun sql-product-font-lock-syntax-alist ()
2656 ;; Change all symbol character to word characters
2658 #'(lambda (entry) (if (string= (substring (cdr entry
) 0 1) "_")
2660 (concat "w" (substring (cdr entry
) 1)))
2662 (sql-get-product-feature sql-product
:syntax-alist
))
2665 (defun sql-highlight-product ()
2666 "Turn on the font highlighting for the SQL product selected."
2667 (when (derived-mode-p 'sql-mode
)
2668 ;; Enhance the syntax table for the product
2669 (set-syntax-table (sql-product-syntax-table))
2672 (sql-product-font-lock nil t
)
2674 ;; Set the mode name to include the product.
2675 (setq mode-name
(concat "SQL[" (or (sql-get-product-feature sql-product
:name
)
2676 (symbol-name sql-product
)) "]"))))
2678 (defun sql-set-product (product)
2679 "Set `sql-product' to PRODUCT and enable appropriate highlighting."
2681 (list (sql-read-product "SQL product: ")))
2682 (if (stringp product
) (setq product
(intern product
)))
2683 (when (not (assoc product sql-product-alist
))
2684 (user-error "SQL product %s is not supported; treated as ANSI" product
)
2685 (setq product
'ansi
))
2687 ;; Save product setting and fontify.
2688 (setq sql-product product
)
2689 (sql-highlight-product))
2692 ;;; Compatibility functions
2694 (if (not (fboundp 'comint-line-beginning-position
))
2695 ;; comint-line-beginning-position is defined in Emacs 21
2696 (defun comint-line-beginning-position ()
2697 "Return the buffer position of the beginning of the line, after any prompt.
2698 The prompt is assumed to be any text at the beginning of the line
2699 matching the regular expression `comint-prompt-regexp', a buffer
2701 (save-excursion (comint-bol nil
) (point))))
2705 ;; Needs a lot more love than I can provide. --Stef
2709 ;; (defconst sql-smie-grammar
2710 ;; (smie-prec2->grammar
2712 ;; ;; Partly based on http://www.h2database.com/html/grammar.html
2713 ;; '((cmd ("SELECT" select-exp "FROM" select-table-exp)
2715 ;; (select-exp ("*") (exp) (exp "AS" column-alias))
2717 ;; (select-table-exp (table-exp "WHERE" exp) (table-exp))
2719 ;; (exp ("CASE" exp "WHEN" exp "THEN" exp "ELSE" exp "END")
2720 ;; ("CASE" exp "WHEN" exp "THEN" exp "END"))
2721 ;; ;; Random ad-hoc additions.
2722 ;; (foo (foo "," foo))
2724 ;; '((assoc ",")))))
2726 ;; (defun sql-smie-rules (kind token)
2727 ;; (pcase (cons kind token)
2728 ;; (`(:list-intro . ,_) t)
2729 ;; (`(:before . "(") (smie-rule-parent))))
2731 ;;; Motion Functions
2733 (defun sql-statement-regexp (prod)
2734 (let* ((ansi-stmt (sql-get-product-feature 'ansi
:statement
))
2735 (prod-stmt (sql-get-product-feature prod
:statement
)))
2739 (concat "\\(" ansi-stmt
"\\|" prod-stmt
"\\)"))
2742 (defun sql-beginning-of-statement (arg)
2743 "Move to the beginning of the current SQL statement."
2746 (let ((here (point))
2747 (regexp (sql-statement-regexp sql-product
))
2750 ;; Go to the end of the statement before the start we desire
2751 (setq last
(or (sql-end-of-statement (- arg
))
2753 ;; And find the end after that
2754 (setq next
(or (sql-end-of-statement 1)
2757 ;; Our start must be between them
2759 ;; Find an beginning-of-stmt that's not in a comment
2760 (while (and (re-search-forward regexp next t
1)
2761 (nth 7 (syntax-ppss)))
2762 (goto-char (match-end 0)))
2768 ;; If we didn't move, try again
2769 (when (= here
(point))
2770 (sql-beginning-of-statement (* 2 (cl-signum arg
))))))
2772 (defun sql-end-of-statement (arg)
2773 "Move to the end of the current SQL statement."
2775 (let ((term (sql-get-product-feature sql-product
:terminator
))
2776 (re-search (if (> 0 arg
) 're-search-backward
're-search-forward
))
2780 (setq term
(car term
)))
2781 ;; Iterate until we've moved the desired number of stmt ends
2782 (while (not (= (cl-signum arg
) 0))
2783 ;; if we're looking at the terminator, jump by 2
2784 (if (or (and (> 0 arg
) (looking-back term
))
2785 (and (< 0 arg
) (looking-at term
)))
2788 ;; If we found another end-of-stmt
2789 (if (not (apply re-search term nil t n nil
))
2791 ;; count it if we're not in a comment
2792 (unless (nth 7 (syntax-ppss))
2793 (setq arg
(- arg
(cl-signum arg
))))))
2794 (goto-char (if (match-data)
2800 (defun sql-magic-go (arg)
2801 "Insert \"o\" and call `comint-send-input'.
2802 `sql-electric-stuff' must be the symbol `go'."
2804 (self-insert-command (prefix-numeric-value arg
))
2805 (if (and (equal sql-electric-stuff
'go
)
2808 (looking-at "go\\b")))
2809 (comint-send-input)))
2810 (put 'sql-magic-go
'delete-selection t
)
2812 (defun sql-magic-semicolon (arg)
2813 "Insert semicolon and call `comint-send-input'.
2814 `sql-electric-stuff' must be the symbol `semicolon'."
2816 (self-insert-command (prefix-numeric-value arg
))
2817 (if (equal sql-electric-stuff
'semicolon
)
2818 (comint-send-input)))
2819 (put 'sql-magic-semicolon
'delete-selection t
)
2821 (defun sql-accumulate-and-indent ()
2822 "Continue SQL statement on the next line."
2824 (if (fboundp 'comint-accumulate
)
2827 (indent-according-to-mode))
2829 (defun sql-help-list-products (indent freep
)
2830 "Generate listing of products available for use under SQLi.
2832 List products with :free-software attribute set to FREEP. Indent
2833 each line with INDENT."
2835 (let (sqli-func doc
)
2837 (dolist (p sql-product-alist
)
2838 (setq sqli-func
(intern (concat "sql-" (symbol-name (car p
)))))
2840 (if (and (fboundp sqli-func
)
2841 (eq (sql-get-product-feature (car p
) :free-software
) freep
))
2845 (or (sql-get-product-feature (car p
) :name
)
2846 (symbol-name (car p
)))
2849 (symbol-name sqli-func
)
2854 "Show short help for the SQL modes."
2856 (describe-function 'sql-help
))
2857 (put 'sql-help
'function-documentation
'(sql--make-help-docstring))
2859 (defvar sql--help-docstring
2860 "Show short help for the SQL modes.
2861 Use an entry function to open an interactive SQL buffer. This buffer is
2862 usually named `*SQL*'. The name of the major mode is SQLi.
2864 Use the following commands to start a specific SQL interpreter:
2868 Other non-free SQL implementations are also supported:
2872 But we urge you to choose a free implementation instead of these.
2874 You can also use \\[sql-product-interactive] to invoke the
2875 interpreter for the current `sql-product'.
2877 Once you have the SQLi buffer, you can enter SQL statements in the
2878 buffer. The output generated is appended to the buffer and a new prompt
2879 is generated. See the In/Out menu in the SQLi buffer for some functions
2880 that help you navigate through the buffer, the input history, etc.
2882 If you have a really complex SQL statement or if you are writing a
2883 procedure, you can do this in a separate buffer. Put the new buffer in
2884 `sql-mode' by calling \\[sql-mode]. The name of this buffer can be
2885 anything. The name of the major mode is SQL.
2887 In this SQL buffer (SQL mode), you can send the region or the entire
2888 buffer to the interactive SQL buffer (SQLi mode). The results are
2889 appended to the SQLi buffer without disturbing your SQL buffer.")
2891 (defun sql--make-help-docstring ()
2892 "Return a docstring for `sql-help' listing loaded SQL products."
2893 (let ((doc sql--help-docstring
))
2894 ;; Insert FREE software list
2895 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]FREE\\s-*$" doc
0)
2896 (setq doc
(replace-match (sql-help-list-products (match-string 1 doc
) t
)
2898 ;; Insert non-FREE software list
2899 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]NONFREE\\s-*$" doc
0)
2900 (setq doc
(replace-match (sql-help-list-products (match-string 1 doc
) nil
)
2904 (defun sql-default-value (var)
2905 "Fetch the value of a variable.
2907 If the current buffer is in `sql-interactive-mode', then fetch
2908 the global value, otherwise use the buffer local value."
2909 (if (derived-mode-p 'sql-interactive-mode
)
2911 (buffer-local-value var
(current-buffer))))
2913 (defun sql-get-login-ext (symbol prompt history-var plist
)
2914 "Prompt user with extended login parameters.
2916 The global value of SYMBOL is the last value and the global value
2917 of the SYMBOL is set based on the user's input.
2919 If PLIST is nil, then the user is simply prompted for a string
2922 The property `:default' specifies the default value. If the
2923 `:number' property is non-nil then ask for a number.
2925 The `:file' property prompts for a file name that must match the
2926 regexp pattern specified in its value.
2928 The `:completion' property prompts for a string specified by its
2929 value. (The property value is used as the PREDICATE argument to
2930 `completing-read'.)"
2933 (let* ((default (plist-get plist
:default
))
2934 (last-value (sql-default-value symbol
))
2937 (if (string-match "\\(\\):[ \t]*\\'" prompt
)
2938 (replace-match (format " (default \"%s\")" default
) t t prompt
1)
2939 (replace-regexp-in-string "[ \t]*\\'"
2940 (format " (default \"%s\") " default
)
2943 (use-dialog-box nil
))
2945 ((plist-member plist
:file
)
2947 (read-file-name prompt
2948 (file-name-directory last-value
) default t
2949 (file-name-nondirectory last-value
)
2950 (when (plist-get plist
:file
)
2953 (concat "\\<" ,(plist-get plist
:file
) "\\>")
2954 (file-name-nondirectory f
)))))))
2956 ((plist-member plist
:completion
)
2957 (completing-read prompt-def
(plist-get plist
:completion
) nil t
2958 last-value history-var default
))
2960 ((plist-get plist
:number
)
2961 (read-number prompt
(or default last-value
0)))
2964 (read-string prompt-def last-value history-var default
))))))
2966 (defun sql-get-login (&rest what
)
2967 "Get username, password and database from the user.
2969 The variables `sql-user', `sql-password', `sql-server', and
2970 `sql-database' can be customized. They are used as the default values.
2971 Usernames, servers and databases are stored in `sql-user-history',
2972 `sql-server-history' and `database-history'. Passwords are not stored
2975 Parameter WHAT is a list of tokens passed as arguments in the
2976 function call. The function asks for the username if WHAT
2977 contains the symbol `user', for the password if it contains the
2978 symbol `password', for the server if it contains the symbol
2979 `server', and for the database if it contains the symbol
2980 `database'. The members of WHAT are processed in the order in
2981 which they are provided.
2983 Each token may also be a list with the token in the car and a
2984 plist of options as the cdr. The following properties are
2987 :file <filename-regexp>
2988 :completion <list-of-strings-or-function>
2989 :default <default-value>
2992 In order to ask the user for username, password and database, call the
2993 function like this: (sql-get-login \\='user \\='password \\='database)."
2995 (let ((plist (cdr-safe w
)))
2996 (pcase (or (car-safe w
) w
)
2998 (sql-get-login-ext 'sql-user
"User: " 'sql-user-history plist
))
3001 (setq-default sql-password
3002 (read-passwd "Password: " nil
(sql-default-value 'sql-password
))))
3005 (sql-get-login-ext 'sql-server
"Server: " 'sql-server-history plist
))
3008 (sql-get-login-ext 'sql-database
"Database: "
3009 'sql-database-history plist
))
3012 (sql-get-login-ext 'sql-port
"Port: "
3013 nil
(append '(:number t
) plist
)))))))
3015 (defun sql-find-sqli-buffer (&optional product connection
)
3016 "Return the name of the current default SQLi buffer or nil.
3017 In order to qualify, the SQLi buffer must be alive, be in
3018 `sql-interactive-mode' and have a process."
3019 (let ((buf sql-buffer
)
3020 (prod (or product sql-product
)))
3022 ;; Current sql-buffer, if there is one.
3023 (and (sql-buffer-live-p buf prod connection
)
3025 ;; Global sql-buffer
3026 (and (setq buf
(default-value 'sql-buffer
))
3027 (sql-buffer-live-p buf prod connection
)
3029 ;; Look thru each buffer
3030 (car (apply #'append
3031 (mapcar #'(lambda (b)
3032 (and (sql-buffer-live-p b prod connection
)
3033 (list (buffer-name b
))))
3036 (defun sql-set-sqli-buffer-generally ()
3037 "Set SQLi buffer for all SQL buffers that have none.
3038 This function checks all SQL buffers for their SQLi buffer. If their
3039 SQLi buffer is nonexistent or has no process, it is set to the current
3040 default SQLi buffer. The current default SQLi buffer is determined
3041 using `sql-find-sqli-buffer'. If `sql-buffer' is set,
3042 `sql-set-sqli-hook' is run."
3045 (let ((buflist (buffer-list))
3046 (default-buffer (sql-find-sqli-buffer)))
3047 (setq-default sql-buffer default-buffer
)
3048 (while (not (null buflist
))
3049 (let ((candidate (car buflist
)))
3050 (set-buffer candidate
)
3051 (if (and (derived-mode-p 'sql-mode
)
3052 (not (sql-buffer-live-p sql-buffer
)))
3054 (setq sql-buffer default-buffer
)
3055 (when default-buffer
3056 (run-hooks 'sql-set-sqli-hook
)))))
3057 (setq buflist
(cdr buflist
))))))
3059 (defun sql-set-sqli-buffer ()
3060 "Set the SQLi buffer SQL strings are sent to.
3062 Call this function in a SQL buffer in order to set the SQLi buffer SQL
3063 strings are sent to. Calling this function sets `sql-buffer' and runs
3064 `sql-set-sqli-hook'.
3066 If you call it from a SQL buffer, this sets the local copy of
3069 If you call it from anywhere else, it sets the global copy of
3072 (let ((default-buffer (sql-find-sqli-buffer)))
3073 (if (null default-buffer
)
3074 (sql-product-interactive)
3075 (let ((new-buffer (read-buffer "New SQLi buffer: " default-buffer t
)))
3076 (if (null (sql-buffer-live-p new-buffer
))
3077 (user-error "Buffer %s is not a working SQLi buffer" new-buffer
)
3079 (setq sql-buffer new-buffer
)
3080 (run-hooks 'sql-set-sqli-hook
)))))))
3082 (defun sql-show-sqli-buffer ()
3083 "Display the current SQLi buffer.
3085 This is the buffer SQL strings are sent to.
3086 It is stored in the variable `sql-buffer'.
3088 See also `sql-help' on how to create such a buffer."
3090 (unless (and sql-buffer
(buffer-live-p (get-buffer sql-buffer
))
3091 (get-buffer-process sql-buffer
))
3092 (sql-set-sqli-buffer))
3093 (display-buffer sql-buffer
))
3095 (defun sql-make-alternate-buffer-name ()
3096 "Return a string that can be used to rename a SQLi buffer.
3097 This is used to set `sql-alternate-buffer-name' within
3098 `sql-interactive-mode'.
3100 If the session was started with `sql-connect' then the alternate
3101 name would be the name of the connection.
3103 Otherwise, it uses the parameters identified by the :sqlilogin
3106 If all else fails, the alternate name would be the user and
3107 server/database name."
3111 ;; Build a name using the :sqli-login setting
3117 (sql-get-product-feature sql-product
:sqli-login
)
3118 #'(lambda (token plist
)
3121 (unless (string= "" sql-user
)
3122 (list "/" sql-user
)))
3124 (unless (or (not (numberp sql-port
))
3126 (list ":" (number-to-string sql-port
))))
3128 (unless (string= "" sql-server
)
3130 (if (plist-member plist
:file
)
3131 (file-name-nondirectory sql-server
)
3134 (unless (string= "" sql-database
)
3136 (if (plist-member plist
:file
)
3137 (file-name-nondirectory sql-database
)
3143 ;; If there's a connection, use it and the name thus far
3145 (format "<%s>%s" sql-connection
(or name
""))
3147 ;; If there is no name, try to create something meaningful
3148 (if (string= "" (or name
""))
3150 (if (string= "" sql-user
)
3151 (if (string= "" (user-login-name))
3153 (concat (user-login-name) "/"))
3154 (concat sql-user
"/"))
3155 (if (string= "" sql-database
)
3156 (if (string= "" sql-server
)
3161 ;; Use the name we've got
3164 (defun sql-rename-buffer (&optional new-name
)
3165 "Rename a SQL interactive buffer.
3167 Prompts for the new name if command is preceded by
3168 \\[universal-argument]. If no buffer name is provided, then the
3169 `sql-alternate-buffer-name' is used.
3171 The actual buffer name set will be \"*SQL: NEW-NAME*\". If
3172 NEW-NAME is empty, then the buffer name will be \"*SQL*\"."
3175 (if (not (derived-mode-p 'sql-interactive-mode
))
3176 (user-error "Current buffer is not a SQL interactive buffer")
3178 (setq sql-alternate-buffer-name
3180 ((stringp new-name
) new-name
)
3182 (read-string "Buffer name (\"*SQL: XXX*\"; enter `XXX'): "
3183 sql-alternate-buffer-name
))
3184 (t sql-alternate-buffer-name
)))
3186 (setq sql-alternate-buffer-name
(substring-no-properties sql-alternate-buffer-name
))
3187 (rename-buffer (if (string= "" sql-alternate-buffer-name
)
3189 (format "*SQL: %s*" sql-alternate-buffer-name
))
3192 (defun sql-copy-column ()
3193 "Copy current column to the end of buffer.
3194 Inserts SELECT or commas if appropriate."
3198 (setq column
(buffer-substring-no-properties
3199 (progn (forward-char 1) (backward-sexp 1) (point))
3200 (progn (forward-sexp 1) (point))))
3201 (goto-char (point-max))
3202 (let ((bol (comint-line-beginning-position)))
3204 ;; if empty command line, insert SELECT
3207 ;; else if appending to INTO .* (, SELECT or ORDER BY, insert a comma
3209 (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+"
3212 ;; else insert a space
3214 (if (eq (preceding-char) ?\s
)
3217 ;; in any case, insert the column
3219 (message "%s" column
))))
3221 ;; On Windows, SQL*Plus for Oracle turns on full buffering for stdout
3222 ;; if it is not attached to a character device; therefore placeholder
3223 ;; replacement by SQL*Plus is fully buffered. The workaround lets
3224 ;; Emacs query for the placeholders.
3226 (defvar sql-placeholder-history nil
3227 "History of placeholder values used.")
3229 (defun sql-placeholders-filter (string)
3230 "Replace placeholders in STRING.
3231 Placeholders are words starting with an ampersand like &this."
3233 (when sql-oracle-scan-on
3234 (while (string-match "&?&\\(\\(?:\\sw\\|\\s_\\)+\\)[.]?" string
)
3235 (setq string
(replace-match
3236 (read-from-minibuffer
3237 (format "Enter value for %s: " (match-string 1 string
))
3238 nil nil nil
'sql-placeholder-history
)
3242 ;; Using DB2 interactively, newlines must be escaped with " \".
3243 ;; The space before the backslash is relevant.
3245 (defun sql-escape-newlines-filter (string)
3246 "Escape newlines in STRING.
3247 Every newline in STRING will be preceded with a space and a backslash."
3248 (if (not sql-db2-escape-newlines
)
3250 (let ((result "") (start 0) mb me
)
3251 (while (string-match "\n" string start
)
3252 (setq mb
(match-beginning 0)
3254 result
(concat result
3255 (substring string start mb
)
3257 (string-equal " \\" (substring string
(- mb
2) mb
)))
3260 (concat result
(substring string start
)))))
3264 ;;; Input sender for SQLi buffers
3266 (defvar sql-output-newline-count
0
3267 "Number of newlines in the input string.
3269 Allows the suppression of continuation prompts.")
3271 (defun sql-input-sender (proc string
)
3272 "Send STRING to PROC after applying filters."
3274 (let* ((product (buffer-local-value 'sql-product
(process-buffer proc
)))
3275 (filter (sql-get-product-feature product
:input-filter
)))
3282 (setq string
(funcall filter string
)))
3284 (mapc #'(lambda (f) (setq string
(funcall f string
))) filter
))
3287 ;; Count how many newlines in the string
3288 (setq sql-output-newline-count
3289 (apply #'+ (mapcar #'(lambda (ch)
3290 (if (eq ch ?
\n) 1 0)) string
)))
3293 (comint-simple-send proc string
)))
3295 ;;; Strip out continuation prompts
3297 (defvar sql-preoutput-hold nil
)
3299 (defun sql-starts-with-prompt-re ()
3300 "Anchor the prompt expression at the beginning of the output line.
3301 Remove the start of line regexp."
3302 (concat "\\`" comint-prompt-regexp
))
3304 (defun sql-ends-with-prompt-re ()
3305 "Anchor the prompt expression at the end of the output line.
3306 Match a SQL prompt or a password prompt."
3307 (concat "\\(?:\\(?:" sql-prompt-regexp
"\\)\\|"
3308 "\\(?:" comint-password-prompt-regexp
"\\)\\)\\'"))
3310 (defun sql-interactive-remove-continuation-prompt (oline)
3311 "Strip out continuation prompts out of the OLINE.
3313 Added to the `comint-preoutput-filter-functions' hook in a SQL
3314 interactive buffer. If `sql-output-newline-count' is greater than
3315 zero, then an output line matching the continuation prompt is filtered
3316 out. If the count is zero, then a newline is inserted into the output
3317 to force the output from the query to appear on a new line.
3319 The complication to this filter is that the continuation prompts
3320 may arrive in multiple chunks. If they do, then the function
3321 saves any unfiltered output in a buffer and prepends that buffer
3322 to the next chunk to properly match the broken-up prompt.
3324 If the filter gets confused, it should reset and stop filtering
3325 to avoid deleting non-prompt output."
3327 ;; continue gathering lines of text iff
3328 ;; + we know what a prompt looks like, and
3329 ;; + there is held text, or
3330 ;; + there are continuation prompt yet to come, or
3331 ;; + not just a prompt string
3332 (when (and comint-prompt-regexp
3333 (or (> (length (or sql-preoutput-hold
"")) 0)
3334 (> (or sql-output-newline-count
0) 0)
3335 (not (or (string-match sql-prompt-regexp oline
)
3336 (string-match sql-prompt-cont-regexp oline
)))))
3339 (let (prompt-found last-nl
)
3341 ;; Add this text to what's left from the last pass
3342 (setq oline
(concat sql-preoutput-hold oline
)
3343 sql-preoutput-hold
"")
3345 ;; If we are looking for multiple prompts
3346 (when (and (integerp sql-output-newline-count
)
3347 (>= sql-output-newline-count
1))
3348 ;; Loop thru each starting prompt and remove it
3349 (let ((start-re (sql-starts-with-prompt-re)))
3350 (while (and (not (string= oline
""))
3351 (> sql-output-newline-count
0)
3352 (string-match start-re oline
))
3353 (setq oline
(replace-match "" nil nil oline
)
3354 sql-output-newline-count
(1- sql-output-newline-count
)
3357 ;; If we've found all the expected prompts, stop looking
3358 (if (= sql-output-newline-count
0)
3359 (setq sql-output-newline-count nil
3360 oline
(concat "\n" oline
))
3362 ;; Still more possible prompts, leave them for the next pass
3363 (setq sql-preoutput-hold oline
3366 ;; If no prompts were found, stop looking
3367 (unless prompt-found
3368 (setq sql-output-newline-count nil
3369 oline
(concat oline sql-preoutput-hold
)
3370 sql-preoutput-hold
""))
3372 ;; Break up output by physical lines if we haven't hit the final prompt
3373 (let ((end-re (sql-ends-with-prompt-re)))
3374 (unless (and (not (string= oline
""))
3375 (string-match end-re oline
)
3376 (>= (match-end 0) (length oline
)))
3377 ;; Find everything upto the last nl
3379 (while (string-match "\n" oline last-nl
)
3380 (setq last-nl
(match-end 0)))
3381 ;; Hold after the last nl, return upto last nl
3382 (setq sql-preoutput-hold
(concat (substring oline last-nl
)
3384 oline
(substring oline
0 last-nl
)))))))
3387 ;;; Sending the region to the SQLi buffer.
3389 (defun sql-send-string (str)
3390 "Send the string STR to the SQL process."
3391 (interactive "sSQL Text: ")
3393 (let ((comint-input-sender-no-newline nil
)
3394 (s (replace-regexp-in-string "[[:space:]\n\r]+\\'" "" str
)))
3395 (if (sql-buffer-live-p sql-buffer
)
3397 ;; Ignore the hoping around...
3399 ;; Set product context
3400 (with-current-buffer sql-buffer
3401 ;; Send the string (trim the trailing whitespace)
3402 (sql-input-sender (get-buffer-process sql-buffer
) s
)
3404 ;; Send a command terminator if we must
3405 (if sql-send-terminator
3406 (sql-send-magic-terminator sql-buffer s sql-send-terminator
))
3408 (message "Sent string to buffer %s" sql-buffer
)))
3410 ;; Display the sql buffer
3411 (if sql-pop-to-buffer-after-send-region
3412 (pop-to-buffer sql-buffer
)
3413 (display-buffer sql-buffer
)))
3415 ;; We don't have no stinkin' sql
3416 (user-error "No SQL process started"))))
3418 (defun sql-send-region (start end
)
3419 "Send a region to the SQL process."
3421 (sql-send-string (buffer-substring-no-properties start end
)))
3423 (defun sql-send-paragraph ()
3424 "Send the current paragraph to the SQL process."
3426 (let ((start (save-excursion
3427 (backward-paragraph)
3429 (end (save-excursion
3432 (sql-send-region start end
)))
3434 (defun sql-send-buffer ()
3435 "Send the buffer contents to the SQL process."
3437 (sql-send-region (point-min) (point-max)))
3439 (defun sql-send-line-and-next ()
3440 "Send the current line to the SQL process and go to the next line."
3442 (sql-send-region (line-beginning-position 1) (line-beginning-position 2))
3443 (beginning-of-line 2)
3444 (while (forward-comment 1))) ; skip all comments and whitespace
3446 (defun sql-send-magic-terminator (buf str terminator
)
3447 "Send TERMINATOR to buffer BUF if its not present in STR."
3448 (let (comint-input-sender-no-newline pat term
)
3449 ;; If flag is merely on(t), get product-specific terminator
3450 (if (eq terminator t
)
3451 (setq terminator
(sql-get-product-feature sql-product
:terminator
)))
3453 ;; If there is no terminator specified, use default ";"
3455 (setq terminator
";"))
3457 ;; Parse the setting into the pattern and the terminator string
3458 (cond ((stringp terminator
)
3459 (setq pat
(regexp-quote terminator
)
3462 (setq pat
(car terminator
)
3463 term
(cdr terminator
)))
3467 ;; Check to see if the pattern is present in the str already sent
3468 (unless (and pat term
3469 (string-match (concat pat
"\\'") str
))
3470 (comint-simple-send (get-buffer-process buf
) term
)
3471 (setq sql-output-newline-count
3472 (if sql-output-newline-count
3473 (1+ sql-output-newline-count
)
3476 (defun sql-remove-tabs-filter (str)
3477 "Replace tab characters with spaces."
3478 (replace-regexp-in-string "\t" " " str nil t
))
3480 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value
)
3481 "Toggle `sql-pop-to-buffer-after-send-region'.
3483 If given the optional parameter VALUE, sets
3484 `sql-toggle-pop-to-buffer-after-send-region' to VALUE."
3487 (setq sql-pop-to-buffer-after-send-region value
)
3488 (setq sql-pop-to-buffer-after-send-region
3489 (null sql-pop-to-buffer-after-send-region
))))
3493 ;;; Redirect output functions
3495 (defvar sql-debug-redirect nil
3496 "If non-nil, display messages related to the use of redirection.")
3498 (defun sql-str-literal (s)
3499 (concat "'" (replace-regexp-in-string "[']" "''" s
) "'"))
3501 (defun sql-redirect (sqlbuf command
&optional outbuf save-prior
)
3502 "Execute the SQL command and send output to OUTBUF.
3504 SQLBUF must be an active SQL interactive buffer. OUTBUF may be
3505 an existing buffer, or the name of a non-existing buffer. If
3506 omitted the output is sent to a temporary buffer which will be
3507 killed after the command completes. COMMAND should be a string
3508 of commands accepted by the SQLi program. COMMAND may also be a
3509 list of SQLi command strings."
3511 (let* ((visible (and outbuf
3512 (not (string= " " (substring outbuf
0 1))))))
3514 (message "Executing SQL command..."))
3516 (mapc #'(lambda (c) (sql-redirect-one sqlbuf c outbuf save-prior
))
3518 (sql-redirect-one sqlbuf command outbuf save-prior
))
3520 (message "Executing SQL command...done"))))
3522 (defun sql-redirect-one (sqlbuf command outbuf save-prior
)
3524 (with-current-buffer sqlbuf
3525 (let ((buf (get-buffer-create (or outbuf
" *SQL-Redirect*")))
3526 (proc (get-buffer-process (current-buffer)))
3527 (comint-prompt-regexp (sql-get-product-feature sql-product
3530 (with-current-buffer buf
3531 (setq-local view-no-disable-on-exit t
)
3535 (goto-char (point-max))
3536 (unless (zerop (buffer-size))
3538 (setq start
(point)))
3540 (when sql-debug-redirect
3541 (message ">>SQL> %S" command
))
3544 (let ((inhibit-quit t
)
3545 comint-preoutput-filter-functions
)
3547 (comint-redirect-send-command-to-process command buf proc nil t
)
3548 (while (or quit-flag
(null comint-redirect-completed
))
3549 (accept-process-output nil
1)))
3552 (comint-redirect-cleanup)
3553 ;; Clean up the output results
3554 (with-current-buffer buf
3555 ;; Remove trailing whitespace
3556 (goto-char (point-max))
3557 (when (looking-back "[ \t\f\n\r]*" start
)
3558 (delete-region (match-beginning 0) (match-end 0)))
3559 ;; Remove echo if there was one
3561 (when (looking-at (concat "^" (regexp-quote command
) "[\\n]"))
3562 (delete-region (match-beginning 0) (match-end 0)))
3565 (while (re-search-forward "\r+$" nil t
)
3566 (replace-match "" t t
))
3567 (goto-char start
))))))))
3569 (defun sql-redirect-value (sqlbuf command regexp
&optional regexp-groups
)
3570 "Execute the SQL command and return part of result.
3572 SQLBUF must be an active SQL interactive buffer. COMMAND should
3573 be a string of commands accepted by the SQLi program. From the
3574 output, the REGEXP is repeatedly matched and the list of
3575 REGEXP-GROUPS submatches is returned. This behaves much like
3576 \\[comint-redirect-results-list-from-process] but instead of
3577 returning a single submatch it returns a list of each submatch
3580 (let ((outbuf " *SQL-Redirect-values*")
3582 (sql-redirect sqlbuf command outbuf nil
)
3583 (with-current-buffer outbuf
3584 (while (re-search-forward regexp nil t
)
3587 ;; no groups-return all of them
3588 ((null regexp-groups
)
3589 (let ((i (/ (length (match-data)) 2))
3593 (push (match-string i
) r
))
3595 ;; one group specified
3596 ((numberp regexp-groups
)
3597 (match-string regexp-groups
))
3598 ;; list of numbers; return the specified matches only
3599 ((consp regexp-groups
)
3600 (mapcar #'(lambda (c)
3602 ((numberp c
) (match-string c
))
3603 ((stringp c
) (match-substitute-replacement c
))
3604 (t (error "sql-redirect-value: unknown REGEXP-GROUPS value - %s" c
))))
3606 ;; String is specified; return replacement string
3607 ((stringp regexp-groups
)
3608 (match-substitute-replacement regexp-groups
))
3610 (error "sql-redirect-value: unknown REGEXP-GROUPS value - %s"
3614 (when sql-debug-redirect
3615 (message ">>SQL> = %S" (reverse results
)))
3617 (nreverse results
)))
3619 (defun sql-execute (sqlbuf outbuf command enhanced arg
)
3620 "Execute a command in a SQL interactive buffer and capture the output.
3622 The commands are run in SQLBUF and the output saved in OUTBUF.
3623 COMMAND must be a string, a function or a list of such elements.
3624 Functions are called with SQLBUF, OUTBUF and ARG as parameters;
3625 strings are formatted with ARG and executed.
3627 If the results are empty the OUTBUF is deleted, otherwise the
3628 buffer is popped into a view window."
3633 (sql-redirect sqlbuf
(if arg
(format c arg
) c
) outbuf
) t
)
3635 (apply c sqlbuf outbuf enhanced arg nil
))
3636 (t (error "Unknown sql-execute item %s" c
))))
3637 (if (consp command
) command
(cons command nil
)))
3639 (setq outbuf
(get-buffer outbuf
))
3640 (if (zerop (buffer-size outbuf
))
3641 (kill-buffer outbuf
)
3642 (let ((one-win (eq (selected-window)
3644 (with-current-buffer outbuf
3645 (set-buffer-modified-p nil
)
3646 (setq-local revert-buffer-function
3647 (lambda (_ignore-auto _noconfirm
)
3648 (sql-execute sqlbuf
(buffer-name outbuf
)
3649 command enhanced arg
)))
3651 (pop-to-buffer outbuf
)
3653 (shrink-window-if-larger-than-buffer)))))
3655 (defun sql-execute-feature (sqlbuf outbuf feature enhanced arg
)
3656 "List objects or details in a separate display buffer."
3658 (product (buffer-local-value 'sql-product
(get-buffer sqlbuf
))))
3659 (setq command
(sql-get-product-feature product feature
))
3661 (error "%s does not support %s" product feature
))
3662 (when (consp command
)
3663 (setq command
(if enhanced
3666 (sql-execute sqlbuf outbuf command enhanced arg
)))
3668 (defvar sql-completion-object nil
3669 "A list of database objects used for completion.
3671 The list is maintained in SQL interactive buffers.")
3673 (defvar sql-completion-column nil
3674 "A list of column names used for completion.
3676 The list is maintained in SQL interactive buffers.")
3678 (defun sql-build-completions-1 (schema completion-list feature
)
3679 "Generate a list of objects in the database for use as completions."
3680 (let ((f (sql-get-product-feature sql-product feature
)))
3682 (set completion-list
3684 (dolist (e (append (symbol-value completion-list
)
3685 (apply f
(current-buffer) (cons schema nil
)))
3687 (unless (member e cl
) (setq cl
(cons e cl
))))
3688 (sort cl
#'string
<))))))
3690 (defun sql-build-completions (schema)
3691 "Generate a list of names in the database for use as completions."
3692 (sql-build-completions-1 schema
'sql-completion-object
:completion-object
)
3693 (sql-build-completions-1 schema
'sql-completion-column
:completion-column
))
3695 (defvar sql-completion-sqlbuf nil
)
3697 (defun sql--completion-table (string pred action
)
3698 (when sql-completion-sqlbuf
3699 (with-current-buffer sql-completion-sqlbuf
3700 (let ((schema (and (string-match "\\`\\(\\sw\\(:?\\sw\\|\\s_\\)*\\)[.]" string
)
3701 (downcase (match-string 1 string
)))))
3703 ;; If we haven't loaded any object name yet, load local schema
3704 (unless sql-completion-object
3705 (sql-build-completions nil
))
3707 ;; If they want another schema, load it if we haven't yet
3709 (let ((schema-dot (concat schema
"."))
3710 (schema-len (1+ (length schema
)))
3711 (names sql-completion-object
)
3714 (while (and (not has-schema
) names
)
3715 (setq has-schema
(and
3716 (>= (length (car names
)) schema-len
)
3718 (downcase (substring (car names
)
3722 (sql-build-completions schema
)))))
3724 ;; Try to find the completion
3725 (complete-with-action action sql-completion-object string pred
))))
3727 (defun sql-read-table-name (prompt)
3728 "Read the name of a database table."
3730 (and (buffer-local-value 'sql-contains-names
(current-buffer))
3731 (thing-at-point-looking-at
3732 (concat "\\_<\\sw\\(:?\\sw\\|\\s_\\)*"
3733 "\\(?:[.]+\\sw\\(?:\\sw\\|\\s_\\)*\\)*\\_>"))
3734 (buffer-substring-no-properties (match-beginning 0)
3736 (sql-completion-sqlbuf (sql-find-sqli-buffer))
3737 (product (when sql-completion-sqlbuf
3738 (with-current-buffer sql-completion-sqlbuf sql-product
)))
3739 (completion-ignore-case t
))
3742 (if (sql-get-product-feature product
:completion-object
)
3743 (completing-read prompt
#'sql--completion-table
3745 (read-from-minibuffer prompt tname
))
3746 (user-error "There is no active SQLi buffer"))))
3748 (defun sql-list-all (&optional enhanced
)
3749 "List all database objects.
3750 With optional prefix argument ENHANCED, displays additional
3751 details or extends the listing to include other schemas objects."
3753 (let ((sqlbuf (sql-find-sqli-buffer)))
3755 (user-error "No SQL interactive buffer found"))
3756 (sql-execute-feature sqlbuf
"*List All*" :list-all enhanced nil
)
3757 (with-current-buffer sqlbuf
3758 ;; Contains the name of database objects
3759 (set (make-local-variable 'sql-contains-names
) t
)
3760 (set (make-local-variable 'sql-buffer
) sqlbuf
))))
3762 (defun sql-list-table (name &optional enhanced
)
3763 "List the details of a database table named NAME.
3764 Displays the columns in the relation. With optional prefix argument
3765 ENHANCED, displays additional details about each column."
3767 (list (sql-read-table-name "Table name: ")
3768 current-prefix-arg
))
3769 (let ((sqlbuf (sql-find-sqli-buffer)))
3771 (user-error "No SQL interactive buffer found"))
3773 (user-error "No table name specified"))
3774 (sql-execute-feature sqlbuf
(format "*List %s*" name
)
3775 :list-table enhanced name
)))
3778 ;;; SQL mode -- uses SQL interactive mode
3781 (define-derived-mode sql-mode prog-mode
"SQL"
3782 "Major mode to edit SQL.
3784 You can send SQL statements to the SQLi buffer using
3785 \\[sql-send-region]. Such a buffer must exist before you can do this.
3786 See `sql-help' on how to create SQLi buffers.
3789 Customization: Entry to this mode runs the `sql-mode-hook'.
3791 When you put a buffer in SQL mode, the buffer stores the last SQLi
3792 buffer created as its destination in the variable `sql-buffer'. This
3793 will be the buffer \\[sql-send-region] sends the region to. If this
3794 SQLi buffer is killed, \\[sql-send-region] is no longer able to
3795 determine where the strings should be sent to. You can set the
3796 value of `sql-buffer' using \\[sql-set-sqli-buffer].
3798 For information on how to create multiple SQLi buffers, see
3799 `sql-interactive-mode'.
3801 Note that SQL doesn't have an escape character unless you specify
3802 one. If you specify backslash as escape character in SQL, you
3803 must tell Emacs. Here's how to do that in your init file:
3805 \(add-hook \\='sql-mode-hook
3807 (modify-syntax-entry ?\\\\ \".\" sql-mode-syntax-table)))"
3809 :abbrev-table sql-mode-abbrev-table
3812 (easy-menu-add sql-mode-menu
)); XEmacs
3814 ;; (smie-setup sql-smie-grammar #'sql-smie-rules)
3815 (set (make-local-variable 'comment-start
) "--")
3816 ;; Make each buffer in sql-mode remember the "current" SQLi buffer.
3817 (make-local-variable 'sql-buffer
)
3818 ;; Add imenu support for sql-mode. Note that imenu-generic-expression
3819 ;; is buffer-local, so we don't need a local-variable for it. SQL is
3820 ;; case-insensitive, that's why we have to set imenu-case-fold-search.
3821 (setq imenu-generic-expression sql-imenu-generic-expression
3822 imenu-case-fold-search t
)
3823 ;; Make `sql-send-paragraph' work on paragraphs that contain indented
3825 (set (make-local-variable 'paragraph-separate
) "[\f]*$")
3826 (set (make-local-variable 'paragraph-start
) "[\n\f]")
3828 (setq-local abbrev-all-caps
1)
3829 ;; Contains the name of database objects
3830 (set (make-local-variable 'sql-contains-names
) t
)
3831 ;; Set syntax and font-face highlighting
3832 ;; Catch changes to sql-product and highlight accordingly
3833 (sql-set-product (or sql-product
'ansi
)) ; Fixes bug#13591
3834 (add-hook 'hack-local-variables-hook
'sql-highlight-product t t
))
3838 ;;; SQL interactive mode
3840 (put 'sql-interactive-mode
'mode-class
'special
)
3841 (put 'sql-interactive-mode
'custom-mode-group
'SQL
)
3843 (defun sql-interactive-mode ()
3844 "Major mode to use a SQL interpreter interactively.
3846 Do not call this function by yourself. The environment must be
3847 initialized by an entry function specific for the SQL interpreter.
3848 See `sql-help' for a list of available entry functions.
3850 \\[comint-send-input] after the end of the process' output sends the
3851 text from the end of process to the end of the current line.
3852 \\[comint-send-input] before end of process output copies the current
3853 line minus the prompt to the end of the buffer and sends it.
3854 \\[comint-copy-old-input] just copies the current line.
3855 Use \\[sql-accumulate-and-indent] to enter multi-line statements.
3857 If you want to make multiple SQL buffers, rename the `*SQL*' buffer
3858 using \\[rename-buffer] or \\[rename-uniquely] and start a new process.
3859 See `sql-help' for a list of available entry functions. The last buffer
3860 created by such an entry function is the current SQLi buffer. SQL
3861 buffers will send strings to the SQLi buffer current at the time of
3862 their creation. See `sql-mode' for details.
3864 Sample session using two connections:
3866 1. Create first SQLi buffer by calling an entry function.
3867 2. Rename buffer \"*SQL*\" to \"*Connection 1*\".
3868 3. Create a SQL buffer \"test1.sql\".
3869 4. Create second SQLi buffer by calling an entry function.
3870 5. Rename buffer \"*SQL*\" to \"*Connection 2*\".
3871 6. Create a SQL buffer \"test2.sql\".
3873 Now \\[sql-send-region] in buffer \"test1.sql\" will send the region to
3874 buffer \"*Connection 1*\", \\[sql-send-region] in buffer \"test2.sql\"
3875 will send the region to buffer \"*Connection 2*\".
3877 If you accidentally suspend your process, use \\[comint-continue-subjob]
3878 to continue it. On some operating systems, this will not work because
3879 the signals are not supported.
3881 \\{sql-interactive-mode-map}
3882 Customization: Entry to this mode runs the hooks on `comint-mode-hook'
3883 and `sql-interactive-mode-hook' (in that order). Before each input, the
3884 hooks on `comint-input-filter-functions' are run. After each SQL
3885 interpreter output, the hooks on `comint-output-filter-functions' are
3888 Variable `sql-input-ring-file-name' controls the initialization of the
3891 Variables `comint-output-filter-functions', a hook, and
3892 `comint-scroll-to-bottom-on-input' and
3893 `comint-scroll-to-bottom-on-output' control whether input and output
3894 cause the window to scroll to the end of the buffer.
3896 If you want to make SQL buffers limited in length, add the function
3897 `comint-truncate-buffer' to `comint-output-filter-functions'.
3899 Here is an example for your init file. It keeps the SQLi buffer a
3902 \(add-hook \\='sql-interactive-mode-hook
3903 (function (lambda ()
3904 (setq comint-output-filter-functions \\='comint-truncate-buffer))))
3906 Here is another example. It will always put point back to the statement
3907 you entered, right above the output it created.
3909 \(setq comint-output-filter-functions
3910 (function (lambda (STR) (comint-show-output))))"
3911 (delay-mode-hooks (comint-mode))
3913 ;; Get the `sql-product' for this interactive session.
3914 (set (make-local-variable 'sql-product
)
3915 (or sql-interactive-product
3919 (setq major-mode
'sql-interactive-mode
)
3921 (concat "SQLi[" (or (sql-get-product-feature sql-product
:name
)
3922 (symbol-name sql-product
)) "]"))
3923 (use-local-map sql-interactive-mode-map
)
3924 (if sql-interactive-mode-menu
3925 (easy-menu-add sql-interactive-mode-menu
)) ; XEmacs
3926 (set-syntax-table sql-mode-syntax-table
)
3928 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
3929 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
3930 ;; will have just one quote. Therefore syntactic highlighting is
3931 ;; disabled for interactive buffers. No imenu support.
3932 (sql-product-font-lock t nil
)
3934 ;; Enable commenting and uncommenting of the region.
3935 (set (make-local-variable 'comment-start
) "--")
3936 ;; Abbreviation table init and case-insensitive. It is not activated
3938 (setq local-abbrev-table sql-mode-abbrev-table
)
3939 (setq abbrev-all-caps
1)
3940 ;; Exiting the process will call sql-stop.
3941 (set-process-sentinel (get-buffer-process (current-buffer)) 'sql-stop
)
3942 ;; Save the connection and login params
3943 (set (make-local-variable 'sql-user
) sql-user
)
3944 (set (make-local-variable 'sql-database
) sql-database
)
3945 (set (make-local-variable 'sql-server
) sql-server
)
3946 (set (make-local-variable 'sql-port
) sql-port
)
3947 (set (make-local-variable 'sql-connection
) sql-connection
)
3948 (setq-default sql-connection nil
)
3949 ;; Contains the name of database objects
3950 (set (make-local-variable 'sql-contains-names
) t
)
3951 ;; Keep track of existing object names
3952 (set (make-local-variable 'sql-completion-object
) nil
)
3953 (set (make-local-variable 'sql-completion-column
) nil
)
3954 ;; Create a useful name for renaming this buffer later.
3955 (set (make-local-variable 'sql-alternate-buffer-name
)
3956 (sql-make-alternate-buffer-name))
3957 ;; User stuff. Initialize before the hook.
3958 (set (make-local-variable 'sql-prompt-regexp
)
3959 (sql-get-product-feature sql-product
:prompt-regexp
))
3960 (set (make-local-variable 'sql-prompt-length
)
3961 (sql-get-product-feature sql-product
:prompt-length
))
3962 (set (make-local-variable 'sql-prompt-cont-regexp
)
3963 (sql-get-product-feature sql-product
:prompt-cont-regexp
))
3964 (make-local-variable 'sql-output-newline-count
)
3965 (make-local-variable 'sql-preoutput-hold
)
3966 (add-hook 'comint-preoutput-filter-functions
3967 'sql-interactive-remove-continuation-prompt nil t
)
3968 (make-local-variable 'sql-input-ring-separator
)
3969 (make-local-variable 'sql-input-ring-file-name
)
3970 ;; Run the mode hook (along with comint's hooks).
3971 (run-mode-hooks 'sql-interactive-mode-hook
)
3972 ;; Set comint based on user overrides.
3973 (setq comint-prompt-regexp
3974 (if sql-prompt-cont-regexp
3975 (concat "\\(" sql-prompt-regexp
3976 "\\|" sql-prompt-cont-regexp
"\\)")
3978 (setq left-margin sql-prompt-length
)
3979 ;; Install input sender
3980 (set (make-local-variable 'comint-input-sender
) 'sql-input-sender
)
3981 ;; People wanting a different history file for each
3982 ;; buffer/process/client/whatever can change separator and file-name
3983 ;; on the sql-interactive-mode-hook.
3985 ((comint-input-ring-separator sql-input-ring-separator
)
3986 (comint-input-ring-file-name sql-input-ring-file-name
))
3987 (comint-read-input-ring t
)))
3989 (defun sql-stop (process event
)
3990 "Called when the SQL process is stopped.
3992 Writes the input history to a history file using
3993 `comint-write-input-ring' and inserts a short message in the SQL buffer.
3995 This function is a sentinel watching the SQL interpreter process.
3996 Sentinels will always get the two parameters PROCESS and EVENT."
3997 (with-current-buffer (process-buffer process
)
3999 ((comint-input-ring-separator sql-input-ring-separator
)
4000 (comint-input-ring-file-name sql-input-ring-file-name
))
4001 (comint-write-input-ring))
4003 (if (not buffer-read-only
)
4004 (insert (format "\nProcess %s %s\n" process event
))
4005 (message "Process %s %s" process event
))))
4009 ;;; Connection handling
4011 (defun sql-read-connection (prompt &optional initial default
)
4012 "Read a connection name."
4013 (let ((completion-ignore-case t
))
4014 (completing-read prompt
4015 (mapcar #'(lambda (c) (car c
))
4016 sql-connection-alist
)
4017 nil t initial
'sql-connection-history default
)))
4020 (defun sql-connect (connection &optional new-name
)
4021 "Connect to an interactive session using CONNECTION settings.
4023 See `sql-connection-alist' to see how to define connections and
4026 The user will not be prompted for any login parameters if a value
4027 is specified in the connection settings."
4029 ;; Prompt for the connection from those defined in the alist
4031 (if sql-connection-alist
4032 (list (sql-read-connection "Connection: " nil
'(nil))
4034 (user-error "No SQL Connections defined")))
4036 ;; Are there connections defined
4037 (if sql-connection-alist
4040 ;; Get connection settings
4041 (let ((connect-set (assoc-string connection sql-connection-alist t
)))
4042 ;; Settings are defined
4044 ;; Set the desired parameters
4045 (let (param-var login-params set-params rem-params
)
4047 ;; :sqli-login params variable
4049 (sql-get-product-feature sql-product
:sqli-login nil t
))
4051 ;; :sqli-login params value
4053 (sql-get-product-feature sql-product
:sqli-login
))
4055 ;; Params in the connection
4061 (`sql-password
'password
)
4062 (`sql-server
'server
)
4063 (`sql-database
'database
)
4068 ;; the remaining params (w/o the connection params)
4070 (sql-for-each-login login-params
4071 #'(lambda (token plist
)
4072 (unless (member token set-params
)
4073 (if plist
(cons token plist
) token
)))))
4075 ;; Set the parameters and start the interactive session
4078 (set-default (car vv
) (eval (cadr vv
))))
4080 (setq-default sql-connection connection
)
4082 ;; Start the SQLi session with revised list of login parameters
4083 (eval `(let ((,param-var
',rem-params
))
4084 (sql-product-interactive ',sql-product
',new-name
))))
4086 (user-error "SQL Connection <%s> does not exist" connection
)
4089 (user-error "No SQL Connections defined")
4092 (defun sql-save-connection (name)
4093 "Captures the connection information of the current SQLi session.
4095 The information is appended to `sql-connection-alist' and
4096 optionally is saved to the user's init file."
4098 (interactive "sNew connection name: ")
4100 (unless (derived-mode-p 'sql-interactive-mode
)
4101 (user-error "Not in a SQL interactive mode!"))
4103 ;; Capture the buffer local settings
4104 (let* ((buf (current-buffer))
4105 (connection (buffer-local-value 'sql-connection buf
))
4106 (product (buffer-local-value 'sql-product buf
))
4107 (user (buffer-local-value 'sql-user buf
))
4108 (database (buffer-local-value 'sql-database buf
))
4109 (server (buffer-local-value 'sql-server buf
))
4110 (port (buffer-local-value 'sql-port buf
)))
4113 (message "This session was started by a connection; it's already been saved.")
4115 (let ((login (sql-get-product-feature product
:sqli-login
))
4116 (alist sql-connection-alist
)
4119 ;; Remove the existing connection if the user says so
4120 (when (and (assoc name alist
)
4121 (yes-or-no-p (format "Replace connection definition <%s>? " name
)))
4122 (setq alist
(assq-delete-all name alist
)))
4124 ;; Add the new connection if it doesn't exist
4125 (if (assoc name alist
)
4126 (user-error "Connection <%s> already exists" name
)
4131 #'(lambda (token _plist
)
4133 (`product
`(sql-product ',product
))
4134 (`user
`(sql-user ,user
))
4135 (`database
`(sql-database ,database
))
4136 (`server
`(sql-server ,server
))
4137 (`port
`(sql-port ,port
)))))))
4139 (setq alist
(append alist
(list connect
)))
4141 ;; confirm whether we want to save the connections
4142 (if (yes-or-no-p "Save the connections for future sessions? ")
4143 (customize-save-variable 'sql-connection-alist alist
)
4144 (customize-set-variable 'sql-connection-alist alist
)))))))
4146 (defun sql-connection-menu-filter (tail)
4147 "Generate menu entries for using each connection."
4152 (format "Connection <%s>\t%s" (car conn
)
4153 (let ((sql-user "") (sql-database "")
4154 (sql-server "") (sql-port 0))
4155 (eval `(let ,(cdr conn
) (sql-make-alternate-buffer-name)))))
4156 (list 'sql-connect
(car conn
))
4158 sql-connection-alist
)
4163 ;;; Entry functions for different SQL interpreters.
4165 (defun sql-product-interactive (&optional product new-name
)
4166 "Run PRODUCT interpreter as an inferior process.
4168 If buffer `*SQL*' exists but no process is running, make a new process.
4169 If buffer exists and a process is running, just switch to buffer `*SQL*'.
4171 To specify the SQL product, prefix the call with
4172 \\[universal-argument]. To set the buffer name as well, prefix
4173 the call to \\[sql-product-interactive] with
4174 \\[universal-argument] \\[universal-argument].
4176 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4179 ;; Handle universal arguments if specified
4180 (when (not (or executing-kbd-macro noninteractive
))
4181 (when (and (consp product
)
4183 (numberp (car product
)))
4184 (when (>= (prefix-numeric-value product
) 16)
4185 (when (not new-name
)
4186 (setq new-name
'(4)))
4187 (setq product
'(4)))))
4189 ;; Get the value of product that we need
4192 ((= (prefix-numeric-value product
) 4) ; C-u, prompt for product
4193 (sql-read-product "SQL product: " sql-product
))
4194 ((and product
; Product specified
4195 (symbolp product
)) product
)
4196 (t sql-product
))) ; Default to sql-product
4198 ;; If we have a product and it has a interactive mode
4200 (when (sql-get-product-feature product
:sqli-comint-func
)
4201 ;; If no new name specified, try to pop to an active SQL
4202 ;; interactive for the same product
4203 (let ((buf (sql-find-sqli-buffer product sql-connection
)))
4204 (if (and (not new-name
) buf
)
4207 ;; We have a new name or sql-buffer doesn't exist or match
4208 ;; Start by remembering where we start
4209 (let ((start-buffer (current-buffer))
4210 new-sqli-buffer rpt
)
4213 (apply #'sql-get-login
4214 (sql-get-product-feature product
:sqli-login
))
4216 ;; Connect to database.
4217 (setq rpt
(make-progress-reporter "Login"))
4219 (let ((sql-user (default-value 'sql-user
))
4220 (sql-password (default-value 'sql-password
))
4221 (sql-server (default-value 'sql-server
))
4222 (sql-database (default-value 'sql-database
))
4223 (sql-port (default-value 'sql-port
))
4224 (default-directory (or sql-default-directory
4225 default-directory
)))
4226 (funcall (sql-get-product-feature product
:sqli-comint-func
)
4228 (sql-get-product-feature product
:sqli-options
)))
4231 (let ((sql-interactive-product product
))
4232 (sql-interactive-mode))
4234 ;; Set the new buffer name
4235 (setq new-sqli-buffer
(current-buffer))
4237 (sql-rename-buffer new-name
))
4238 (set (make-local-variable 'sql-buffer
)
4239 (buffer-name new-sqli-buffer
))
4241 ;; Set `sql-buffer' in the start buffer
4242 (with-current-buffer start-buffer
4243 (when (derived-mode-p 'sql-mode
)
4244 (setq sql-buffer
(buffer-name new-sqli-buffer
))
4245 (run-hooks 'sql-set-sqli-hook
)))
4247 ;; Make sure the connection is complete
4248 ;; (Sometimes start up can be slow)
4249 ;; and call the login hook
4250 (let ((proc (get-buffer-process new-sqli-buffer
))
4251 (secs sql-login-delay
)
4253 (while (and (memq (process-status proc
) '(open run
))
4254 (or (accept-process-output proc step
)
4255 (<= 0.0 (setq secs
(- secs step
))))
4256 (progn (goto-char (point-max))
4257 (not (re-search-backward sql-prompt-regexp
0 t
))))
4258 (progress-reporter-update rpt
)))
4260 (goto-char (point-max))
4261 (when (re-search-backward sql-prompt-regexp nil t
)
4262 (run-hooks 'sql-login-hook
))
4265 (progress-reporter-done rpt
)
4266 (pop-to-buffer new-sqli-buffer
)
4267 (goto-char (point-max))
4268 (current-buffer)))))
4269 (user-error "No default SQL product defined. Set `sql-product'.")))
4271 (defun sql-comint (product params
)
4272 "Set up a comint buffer to run the SQL processor.
4274 PRODUCT is the SQL product. PARAMS is a list of strings which are
4275 passed as command line arguments."
4276 (let ((program (sql-get-product-feature product
:sqli-program
))
4278 ;; Make sure we can find the program. `executable-find' does not
4279 ;; work for remote hosts; we suppress the check there.
4280 (unless (or (file-remote-p default-directory
)
4281 (executable-find program
))
4282 (error "Unable to locate SQL program `%s'" program
))
4283 ;; Make sure buffer name is unique.
4284 (when (sql-buffer-live-p (format "*%s*" buf-name
))
4285 (setq buf-name
(format "SQL-%s" product
))
4286 (when (sql-buffer-live-p (format "*%s*" buf-name
))
4288 (while (sql-buffer-live-p
4290 (setq buf-name
(format "SQL-%s%d" product i
))))
4293 (apply #'make-comint buf-name program nil params
))))
4296 (defun sql-oracle (&optional buffer
)
4297 "Run sqlplus by Oracle as an inferior process.
4299 If buffer `*SQL*' exists but no process is running, make a new process.
4300 If buffer exists and a process is running, just switch to buffer
4303 Interpreter used comes from variable `sql-oracle-program'. Login uses
4304 the variables `sql-user', `sql-password', and `sql-database' as
4305 defaults, if set. Additional command line parameters can be stored in
4306 the list `sql-oracle-options'.
4308 The buffer is put in SQL interactive mode, giving commands for sending
4309 input. See `sql-interactive-mode'.
4311 To set the buffer name directly, use \\[universal-argument]
4312 before \\[sql-oracle]. Once session has started,
4313 \\[sql-rename-buffer] can be called separately to rename the
4316 To specify a coding system for converting non-ASCII characters
4317 in the input and output to the process, use \\[universal-coding-system-argument]
4318 before \\[sql-oracle]. You can also specify this with \\[set-buffer-process-coding-system]
4319 in the SQL buffer, after you start the process.
4320 The default comes from `process-coding-system-alist' and
4321 `default-process-coding-system'.
4323 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4325 (sql-product-interactive 'oracle buffer
))
4327 (defun sql-comint-oracle (product options
)
4328 "Create comint buffer and connect to Oracle."
4329 ;; Produce user/password@database construct. Password without user
4330 ;; is meaningless; database without user/password is meaningless,
4331 ;; because "@param" will ask sqlplus to interpret the script
4333 (let (parameter nlslang coding
)
4334 (if (not (string= "" sql-user
))
4335 (if (not (string= "" sql-password
))
4336 (setq parameter
(concat sql-user
"/" sql-password
))
4337 (setq parameter sql-user
)))
4338 (if (and parameter
(not (string= "" sql-database
)))
4339 (setq parameter
(concat parameter
"@" sql-database
)))
4340 ;; options must appear before the logon parameters
4342 (setq parameter
(append options
(list parameter
)))
4343 (setq parameter options
))
4344 (sql-comint product parameter
)
4345 ;; Set process coding system to agree with the interpreter
4346 (setq nlslang
(or (getenv "NLS_LANG") "")
4348 ;; Are we missing any common NLS character sets
4349 '(("US8PC437" . cp437
)
4350 ("EL8PC737" . cp737
)
4351 ("WE8PC850" . cp850
)
4352 ("EE8PC852" . cp852
)
4353 ("TR8PC857" . cp857
)
4354 ("WE8PC858" . cp858
)
4355 ("IS8PC861" . cp861
)
4356 ("IW8PC1507" . cp862
)
4358 ("RU8PC866" . cp866
)
4359 ("US7ASCII" . us-ascii
)
4361 ("AL32UTF8" . utf-8
)
4362 ("AL16UTF16" . utf-16
))
4364 (when (string-match (format "\\.%s\\'" (car cs
)) nlslang
)
4365 (setq coding
(cdr cs
)))))
4366 (set-buffer-process-coding-system coding coding
)))
4368 (defun sql-oracle-save-settings (sqlbuf)
4369 "Save most SQL*Plus settings so they may be reset by \\[sql-redirect]."
4370 ;; Note: does not capture the following settings:
4380 ;; SQLPLUSCOMPATIBILITY
4386 ;; (apply #'concat (append
4392 (concat "SHOW ARRAYSIZE AUTOCOMMIT AUTOPRINT AUTORECOVERY AUTOTRACE"
4393 " CMDSEP COLSEP COPYCOMMIT DESCRIBE ECHO EDITFILE EMBEDDED"
4394 " ESCAPE FLAGGER FLUSH HEADING INSTANCE LINESIZE LNO LOBOFFSET"
4395 " LOGSOURCE LONG LONGCHUNKSIZE NEWPAGE NULL NUMFORMAT NUMWIDTH"
4396 " PAGESIZE PAUSE PNO RECSEP SERVEROUTPUT SHIFTINOUT SHOWMODE"
4397 " SPOOL SQLBLANKLINES SQLCASE SQLCODE SQLCONTINUE SQLNUMBER"
4398 " SQLPROMPT SUFFIX TAB TERMOUT TIMING TRIMOUT TRIMSPOOL VERIFY")
4402 ;; option "c" (hex xx)
4405 (concat "SHOW BLOCKTERMINATOR CONCAT DEFINE SQLPREFIX SQLTERMINATOR"
4406 " UNDERLINE HEADSEP RECSEPCHAR")
4407 "^\\(.+\\) (hex ..)$"
4410 ;; FEEDBACK ON for 99 or more rows
4415 "^\\(?:FEEDBACK ON for \\([[:digit:]]+\\) or more rows\\|feedback \\(OFF\\)\\)"
4416 "SET FEEDBACK \\1\\2")
4418 ;; wrap : lines will be wrapped
4419 ;; wrap : lines will be truncated
4420 (list (concat "SET WRAP "
4422 (car (sql-redirect-value
4425 "^wrap : lines will be \\(wrapped\\|truncated\\)" 1))
4429 (defun sql-oracle-restore-settings (sqlbuf saved-settings
)
4430 "Restore the SQL*Plus settings in SAVED-SETTINGS."
4432 ;; Remove any settings that haven't changed
4434 #'(lambda (one-cur-setting)
4435 (setq saved-settings
(delete one-cur-setting saved-settings
)))
4436 (sql-oracle-save-settings sqlbuf
))
4438 ;; Restore the changed settings
4439 (sql-redirect sqlbuf saved-settings
))
4441 (defun sql-oracle-list-all (sqlbuf outbuf enhanced _table-name
)
4442 ;; Query from USER_OBJECTS or ALL_OBJECTS
4443 (let ((settings (sql-oracle-save-settings sqlbuf
))
4446 "SELECT INITCAP(x.object_type) AS SQL_EL_TYPE "
4447 ", x.object_name AS SQL_EL_NAME "
4448 "FROM user_objects x "
4449 "WHERE x.object_type NOT LIKE '%% BODY' "
4453 "SELECT INITCAP(x.object_type) AS SQL_EL_TYPE "
4454 ", x.owner ||'.'|| x.object_name AS SQL_EL_NAME "
4455 "FROM all_objects x "
4456 "WHERE x.object_type NOT LIKE '%% BODY' "
4457 "AND x.owner <> 'SYS' "
4460 (sql-redirect sqlbuf
4461 (concat "SET LINESIZE 80 PAGESIZE 50000 TRIMOUT ON"
4462 " TAB OFF TIMING OFF FEEDBACK OFF"))
4464 (sql-redirect sqlbuf
4465 (list "COLUMN SQL_EL_TYPE HEADING \"Type\" FORMAT A19"
4466 "COLUMN SQL_EL_NAME HEADING \"Name\""
4467 (format "COLUMN SQL_EL_NAME FORMAT A%d"
4468 (if enhanced
60 35))))
4470 (sql-redirect sqlbuf
4471 (if enhanced enhanced-sql simple-sql
)
4474 (sql-redirect sqlbuf
4475 '("COLUMN SQL_EL_NAME CLEAR"
4476 "COLUMN SQL_EL_TYPE CLEAR"))
4478 (sql-oracle-restore-settings sqlbuf settings
)))
4480 (defun sql-oracle-list-table (sqlbuf outbuf _enhanced table-name
)
4481 "Implements :list-table under Oracle."
4482 (let ((settings (sql-oracle-save-settings sqlbuf
)))
4484 (sql-redirect sqlbuf
4486 (concat "SET LINESIZE %d PAGESIZE 50000"
4487 " DESCRIBE DEPTH 1 LINENUM OFF INDENT ON")
4488 (max 65 (min 120 (window-width)))))
4490 (sql-redirect sqlbuf
(format "DESCRIBE %s" table-name
)
4493 (sql-oracle-restore-settings sqlbuf settings
)))
4495 (defcustom sql-oracle-completion-types
'("FUNCTION" "PACKAGE" "PROCEDURE"
4496 "SEQUENCE" "SYNONYM" "TABLE" "TRIGGER"
4498 "List of object types to include for completion under Oracle.
4500 See the distinct values in ALL_OBJECTS.OBJECT_TYPE for possible values."
4502 :type
'(repeat string
)
4505 (defun sql-oracle-completion-object (sqlbuf schema
)
4511 (format "owner||'.'||object_name AS o FROM all_objects WHERE owner = %s AND "
4512 (sql-str-literal (upcase schema
)))
4513 "object_name AS o FROM user_objects WHERE ")
4514 "temporary = 'N' AND generated = 'N' AND secondary = 'N' AND "
4516 (mapconcat (function sql-str-literal
) sql-oracle-completion-types
",")
4518 "^[\001]\\(.+\\)$" 1))
4522 (defun sql-sybase (&optional buffer
)
4523 "Run isql by Sybase as an inferior process.
4525 If buffer `*SQL*' exists but no process is running, make a new process.
4526 If buffer exists and a process is running, just switch to buffer
4529 Interpreter used comes from variable `sql-sybase-program'. Login uses
4530 the variables `sql-server', `sql-user', `sql-password', and
4531 `sql-database' as defaults, if set. Additional command line parameters
4532 can be stored in the list `sql-sybase-options'.
4534 The buffer is put in SQL interactive mode, giving commands for sending
4535 input. See `sql-interactive-mode'.
4537 To set the buffer name directly, use \\[universal-argument]
4538 before \\[sql-sybase]. Once session has started,
4539 \\[sql-rename-buffer] can be called separately to rename the
4542 To specify a coding system for converting non-ASCII characters
4543 in the input and output to the process, use \\[universal-coding-system-argument]
4544 before \\[sql-sybase]. You can also specify this with \\[set-buffer-process-coding-system]
4545 in the SQL buffer, after you start the process.
4546 The default comes from `process-coding-system-alist' and
4547 `default-process-coding-system'.
4549 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4551 (sql-product-interactive 'sybase buffer
))
4553 (defun sql-comint-sybase (product options
)
4554 "Create comint buffer and connect to Sybase."
4555 ;; Put all parameters to the program (if defined) in a list and call
4559 (if (not (string= "" sql-user
))
4560 (list "-U" sql-user
))
4561 (if (not (string= "" sql-password
))
4562 (list "-P" sql-password
))
4563 (if (not (string= "" sql-database
))
4564 (list "-D" sql-database
))
4565 (if (not (string= "" sql-server
))
4566 (list "-S" sql-server
))
4568 (sql-comint product params
)))
4573 (defun sql-informix (&optional buffer
)
4574 "Run dbaccess by Informix as an inferior process.
4576 If buffer `*SQL*' exists but no process is running, make a new process.
4577 If buffer exists and a process is running, just switch to buffer
4580 Interpreter used comes from variable `sql-informix-program'. Login uses
4581 the variable `sql-database' as default, if set.
4583 The buffer is put in SQL interactive mode, giving commands for sending
4584 input. See `sql-interactive-mode'.
4586 To set the buffer name directly, use \\[universal-argument]
4587 before \\[sql-informix]. Once session has started,
4588 \\[sql-rename-buffer] can be called separately to rename the
4591 To specify a coding system for converting non-ASCII characters
4592 in the input and output to the process, use \\[universal-coding-system-argument]
4593 before \\[sql-informix]. You can also specify this with \\[set-buffer-process-coding-system]
4594 in the SQL buffer, after you start the process.
4595 The default comes from `process-coding-system-alist' and
4596 `default-process-coding-system'.
4598 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4600 (sql-product-interactive 'informix buffer
))
4602 (defun sql-comint-informix (product options
)
4603 "Create comint buffer and connect to Informix."
4604 ;; username and password are ignored.
4605 (let ((db (if (string= "" sql-database
)
4607 (if (string= "" sql-server
)
4609 (concat sql-database
"@" sql-server
)))))
4610 (sql-comint product
(append `(,db
"-") options
))))
4615 (defun sql-sqlite (&optional buffer
)
4616 "Run sqlite as an inferior process.
4618 SQLite is free software.
4620 If buffer `*SQL*' exists but no process is running, make a new process.
4621 If buffer exists and a process is running, just switch to buffer
4624 Interpreter used comes from variable `sql-sqlite-program'. Login uses
4625 the variables `sql-user', `sql-password', `sql-database', and
4626 `sql-server' as defaults, if set. Additional command line parameters
4627 can be stored in the list `sql-sqlite-options'.
4629 The buffer is put in SQL interactive mode, giving commands for sending
4630 input. See `sql-interactive-mode'.
4632 To set the buffer name directly, use \\[universal-argument]
4633 before \\[sql-sqlite]. Once session has started,
4634 \\[sql-rename-buffer] can be called separately to rename the
4637 To specify a coding system for converting non-ASCII characters
4638 in the input and output to the process, use \\[universal-coding-system-argument]
4639 before \\[sql-sqlite]. You can also specify this with \\[set-buffer-process-coding-system]
4640 in the SQL buffer, after you start the process.
4641 The default comes from `process-coding-system-alist' and
4642 `default-process-coding-system'.
4644 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4646 (sql-product-interactive 'sqlite buffer
))
4648 (defun sql-comint-sqlite (product options
)
4649 "Create comint buffer and connect to SQLite."
4650 ;; Put all parameters to the program (if defined) in a list and call
4654 (if (not (string= "" sql-database
))
4655 `(,(expand-file-name sql-database
))))))
4656 (sql-comint product params
)))
4658 (defun sql-sqlite-completion-object (sqlbuf _schema
)
4659 (sql-redirect-value sqlbuf
".tables" "\\sw\\(?:\\sw\\|\\s_\\)*" 0))
4664 (defun sql-mysql (&optional buffer
)
4665 "Run mysql by TcX as an inferior process.
4667 Mysql versions 3.23 and up are free software.
4669 If buffer `*SQL*' exists but no process is running, make a new process.
4670 If buffer exists and a process is running, just switch to buffer
4673 Interpreter used comes from variable `sql-mysql-program'. Login uses
4674 the variables `sql-user', `sql-password', `sql-database', and
4675 `sql-server' as defaults, if set. Additional command line parameters
4676 can be stored in the list `sql-mysql-options'.
4678 The buffer is put in SQL interactive mode, giving commands for sending
4679 input. See `sql-interactive-mode'.
4681 To set the buffer name directly, use \\[universal-argument]
4682 before \\[sql-mysql]. Once session has started,
4683 \\[sql-rename-buffer] can be called separately to rename the
4686 To specify a coding system for converting non-ASCII characters
4687 in the input and output to the process, use \\[universal-coding-system-argument]
4688 before \\[sql-mysql]. You can also specify this with \\[set-buffer-process-coding-system]
4689 in the SQL buffer, after you start the process.
4690 The default comes from `process-coding-system-alist' and
4691 `default-process-coding-system'.
4693 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4695 (sql-product-interactive 'mysql buffer
))
4697 (defun sql-comint-mysql (product options
)
4698 "Create comint buffer and connect to MySQL."
4699 ;; Put all parameters to the program (if defined) in a list and call
4704 (if (not (string= "" sql-user
))
4705 (list (concat "--user=" sql-user
)))
4706 (if (not (string= "" sql-password
))
4707 (list (concat "--password=" sql-password
)))
4708 (if (not (= 0 sql-port
))
4709 (list (concat "--port=" (number-to-string sql-port
))))
4710 (if (not (string= "" sql-server
))
4711 (list (concat "--host=" sql-server
)))
4712 (if (not (string= "" sql-database
))
4713 (list sql-database
)))))
4714 (sql-comint product params
)))
4719 (defun sql-solid (&optional buffer
)
4720 "Run solsql by Solid as an inferior process.
4722 If buffer `*SQL*' exists but no process is running, make a new process.
4723 If buffer exists and a process is running, just switch to buffer
4726 Interpreter used comes from variable `sql-solid-program'. Login uses
4727 the variables `sql-user', `sql-password', and `sql-server' as
4730 The buffer is put in SQL interactive mode, giving commands for sending
4731 input. See `sql-interactive-mode'.
4733 To set the buffer name directly, use \\[universal-argument]
4734 before \\[sql-solid]. Once session has started,
4735 \\[sql-rename-buffer] can be called separately to rename the
4738 To specify a coding system for converting non-ASCII characters
4739 in the input and output to the process, use \\[universal-coding-system-argument]
4740 before \\[sql-solid]. You can also specify this with \\[set-buffer-process-coding-system]
4741 in the SQL buffer, after you start the process.
4742 The default comes from `process-coding-system-alist' and
4743 `default-process-coding-system'.
4745 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4747 (sql-product-interactive 'solid buffer
))
4749 (defun sql-comint-solid (product options
)
4750 "Create comint buffer and connect to Solid."
4751 ;; Put all parameters to the program (if defined) in a list and call
4755 (if (not (string= "" sql-server
))
4757 ;; It only makes sense if both username and password are there.
4758 (if (not (or (string= "" sql-user
)
4759 (string= "" sql-password
)))
4760 (list sql-user sql-password
))
4762 (sql-comint product params
)))
4767 (defun sql-ingres (&optional buffer
)
4768 "Run sql by Ingres as an inferior process.
4770 If buffer `*SQL*' exists but no process is running, make a new process.
4771 If buffer exists and a process is running, just switch to buffer
4774 Interpreter used comes from variable `sql-ingres-program'. Login uses
4775 the variable `sql-database' as default, if set.
4777 The buffer is put in SQL interactive mode, giving commands for sending
4778 input. See `sql-interactive-mode'.
4780 To set the buffer name directly, use \\[universal-argument]
4781 before \\[sql-ingres]. Once session has started,
4782 \\[sql-rename-buffer] can be called separately to rename the
4785 To specify a coding system for converting non-ASCII characters
4786 in the input and output to the process, use \\[universal-coding-system-argument]
4787 before \\[sql-ingres]. You can also specify this with \\[set-buffer-process-coding-system]
4788 in the SQL buffer, after you start the process.
4789 The default comes from `process-coding-system-alist' and
4790 `default-process-coding-system'.
4792 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4794 (sql-product-interactive 'ingres buffer
))
4796 (defun sql-comint-ingres (product options
)
4797 "Create comint buffer and connect to Ingres."
4798 ;; username and password are ignored.
4800 (append (if (string= "" sql-database
)
4802 (list sql-database
))
4808 (defun sql-ms (&optional buffer
)
4809 "Run osql by Microsoft as an inferior process.
4811 If buffer `*SQL*' exists but no process is running, make a new process.
4812 If buffer exists and a process is running, just switch to buffer
4815 Interpreter used comes from variable `sql-ms-program'. Login uses the
4816 variables `sql-user', `sql-password', `sql-database', and `sql-server'
4817 as defaults, if set. Additional command line parameters can be stored
4818 in the list `sql-ms-options'.
4820 The buffer is put in SQL interactive mode, giving commands for sending
4821 input. See `sql-interactive-mode'.
4823 To set the buffer name directly, use \\[universal-argument]
4824 before \\[sql-ms]. Once session has started,
4825 \\[sql-rename-buffer] can be called separately to rename the
4828 To specify a coding system for converting non-ASCII characters
4829 in the input and output to the process, use \\[universal-coding-system-argument]
4830 before \\[sql-ms]. You can also specify this with \\[set-buffer-process-coding-system]
4831 in the SQL buffer, after you start the process.
4832 The default comes from `process-coding-system-alist' and
4833 `default-process-coding-system'.
4835 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4837 (sql-product-interactive 'ms buffer
))
4839 (defun sql-comint-ms (product options
)
4840 "Create comint buffer and connect to Microsoft SQL Server."
4841 ;; Put all parameters to the program (if defined) in a list and call
4845 (if (not (string= "" sql-user
))
4846 (list "-U" sql-user
))
4847 (if (not (string= "" sql-database
))
4848 (list "-d" sql-database
))
4849 (if (not (string= "" sql-server
))
4850 (list "-S" sql-server
))
4853 (if (not (string= "" sql-password
))
4854 `("-P" ,sql-password
,@params
)
4855 (if (string= "" sql-user
)
4856 ;; If neither user nor password is provided, use system
4859 ;; If -P is passed to ISQL as the last argument without a
4860 ;; password, it's considered null.
4862 (sql-comint product params
)))
4867 (defun sql-postgres (&optional buffer
)
4868 "Run psql by Postgres as an inferior process.
4870 If buffer `*SQL*' exists but no process is running, make a new process.
4871 If buffer exists and a process is running, just switch to buffer
4874 Interpreter used comes from variable `sql-postgres-program'. Login uses
4875 the variables `sql-database' and `sql-server' as default, if set.
4876 Additional command line parameters can be stored in the list
4877 `sql-postgres-options'.
4879 The buffer is put in SQL interactive mode, giving commands for sending
4880 input. See `sql-interactive-mode'.
4882 To set the buffer name directly, use \\[universal-argument]
4883 before \\[sql-postgres]. Once session has started,
4884 \\[sql-rename-buffer] can be called separately to rename the
4887 To specify a coding system for converting non-ASCII characters
4888 in the input and output to the process, use \\[universal-coding-system-argument]
4889 before \\[sql-postgres]. You can also specify this with \\[set-buffer-process-coding-system]
4890 in the SQL buffer, after you start the process.
4891 The default comes from `process-coding-system-alist' and
4892 `default-process-coding-system'. If your output lines end with ^M,
4893 your might try undecided-dos as a coding system. If this doesn't help,
4894 Try to set `comint-output-filter-functions' like this:
4896 \(setq comint-output-filter-functions (append comint-output-filter-functions
4897 \\='(comint-strip-ctrl-m)))
4899 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4901 (sql-product-interactive 'postgres buffer
))
4903 (defun sql-comint-postgres (product options
)
4904 "Create comint buffer and connect to Postgres."
4905 ;; username and password are ignored. Mark Stosberg suggests to add
4906 ;; the database at the end. Jason Beegan suggests using --pset and
4907 ;; pager=off instead of \\o|cat. The later was the solution by
4908 ;; Gregor Zych. Jason's suggestion is the default value for
4909 ;; sql-postgres-options.
4912 (if (not (= 0 sql-port
))
4913 (list "-p" (number-to-string sql-port
)))
4914 (if (not (string= "" sql-user
))
4915 (list "-U" sql-user
))
4916 (if (not (string= "" sql-server
))
4917 (list "-h" sql-server
))
4919 (if (not (string= "" sql-database
))
4920 (list sql-database
)))))
4921 (sql-comint product params
)))
4923 (defun sql-postgres-completion-object (sqlbuf schema
)
4924 (sql-redirect sqlbuf
"\\t on")
4927 (car (sql-redirect-value
4929 "Output format is \\(.*\\)[.]$" 1)))))
4931 (sql-redirect sqlbuf
"\\a"))
4932 (let* ((fs (or (car (sql-redirect-value
4933 sqlbuf
"\\f" "Field separator is \"\\(.\\)[.]$" 1))
4935 (re (concat "^\\([^" fs
"]*\\)" fs
"\\([^" fs
"]*\\)"
4936 fs
"[^" fs
"]*" fs
"[^" fs
"]*$"))
4937 (cl (if (not schema
)
4938 (sql-redirect-value sqlbuf
"\\d" re
'(1 2))
4939 (append (sql-redirect-value
4940 sqlbuf
(format "\\dt %s.*" schema
) re
'(1 2))
4942 sqlbuf
(format "\\dv %s.*" schema
) re
'(1 2))
4944 sqlbuf
(format "\\ds %s.*" schema
) re
'(1 2))))))
4946 ;; Restore tuples and alignment to what they were.
4947 (sql-redirect sqlbuf
"\\t off")
4949 (sql-redirect sqlbuf
"\\a"))
4951 ;; Return the list of table names (public schema name can be omitted)
4952 (mapcar #'(lambda (tbl)
4953 (if (string= (car tbl
) "public")
4954 (format "\"%s\"" (cadr tbl
))
4955 (format "\"%s\".\"%s\"" (car tbl
) (cadr tbl
))))
4961 (defun sql-interbase (&optional buffer
)
4962 "Run isql by Interbase as an inferior process.
4964 If buffer `*SQL*' exists but no process is running, make a new process.
4965 If buffer exists and a process is running, just switch to buffer
4968 Interpreter used comes from variable `sql-interbase-program'. Login
4969 uses the variables `sql-user', `sql-password', and `sql-database' as
4972 The buffer is put in SQL interactive mode, giving commands for sending
4973 input. See `sql-interactive-mode'.
4975 To set the buffer name directly, use \\[universal-argument]
4976 before \\[sql-interbase]. Once session has started,
4977 \\[sql-rename-buffer] can be called separately to rename the
4980 To specify a coding system for converting non-ASCII characters
4981 in the input and output to the process, use \\[universal-coding-system-argument]
4982 before \\[sql-interbase]. You can also specify this with \\[set-buffer-process-coding-system]
4983 in the SQL buffer, after you start the process.
4984 The default comes from `process-coding-system-alist' and
4985 `default-process-coding-system'.
4987 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4989 (sql-product-interactive 'interbase buffer
))
4991 (defun sql-comint-interbase (product options
)
4992 "Create comint buffer and connect to Interbase."
4993 ;; Put all parameters to the program (if defined) in a list and call
4997 (if (not (string= "" sql-database
))
4998 (list sql-database
)) ; Add to the front!
4999 (if (not (string= "" sql-password
))
5000 (list "-p" sql-password
))
5001 (if (not (string= "" sql-user
))
5002 (list "-u" sql-user
))
5004 (sql-comint product params
)))
5009 (defun sql-db2 (&optional buffer
)
5010 "Run db2 by IBM as an inferior process.
5012 If buffer `*SQL*' exists but no process is running, make a new process.
5013 If buffer exists and a process is running, just switch to buffer
5016 Interpreter used comes from variable `sql-db2-program'. There is not
5019 The buffer is put in SQL interactive mode, giving commands for sending
5020 input. See `sql-interactive-mode'.
5022 If you use \\[sql-accumulate-and-indent] to send multiline commands to
5023 db2, newlines will be escaped if necessary. If you don't want that, set
5024 `comint-input-sender' back to `comint-simple-send' by writing an after
5025 advice. See the elisp manual for more information.
5027 To set the buffer name directly, use \\[universal-argument]
5028 before \\[sql-db2]. Once session has started,
5029 \\[sql-rename-buffer] can be called separately to rename the
5032 To specify a coding system for converting non-ASCII characters
5033 in the input and output to the process, use \\[universal-coding-system-argument]
5034 before \\[sql-db2]. You can also specify this with \\[set-buffer-process-coding-system]
5035 in the SQL buffer, after you start the process.
5036 The default comes from `process-coding-system-alist' and
5037 `default-process-coding-system'.
5039 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
5041 (sql-product-interactive 'db2 buffer
))
5043 (defun sql-comint-db2 (product options
)
5044 "Create comint buffer and connect to DB2."
5045 ;; Put all parameters to the program (if defined) in a list and call
5047 (sql-comint product options
))
5050 (defun sql-linter (&optional buffer
)
5051 "Run inl by RELEX as an inferior process.
5053 If buffer `*SQL*' exists but no process is running, make a new process.
5054 If buffer exists and a process is running, just switch to buffer
5057 Interpreter used comes from variable `sql-linter-program' - usually `inl'.
5058 Login uses the variables `sql-user', `sql-password', `sql-database' and
5059 `sql-server' as defaults, if set. Additional command line parameters
5060 can be stored in the list `sql-linter-options'. Run inl -h to get help on
5063 `sql-database' is used to set the LINTER_MBX environment variable for
5064 local connections, `sql-server' refers to the server name from the
5065 `nodetab' file for the network connection (dbc_tcp or friends must run
5066 for this to work). If `sql-password' is an empty string, inl will use
5069 The buffer is put in SQL interactive mode, giving commands for sending
5070 input. See `sql-interactive-mode'.
5072 To set the buffer name directly, use \\[universal-argument]
5073 before \\[sql-linter]. Once session has started,
5074 \\[sql-rename-buffer] can be called separately to rename the
5077 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
5079 (sql-product-interactive 'linter buffer
))
5081 (defun sql-comint-linter (product options
)
5082 "Create comint buffer and connect to Linter."
5083 ;; Put all parameters to the program (if defined) in a list and call
5086 (if (not (string= "" sql-user
))
5087 (concat sql-user
"/" sql-password
)))
5090 (if (not (string= "" sql-server
))
5091 (list "-n" sql-server
))
5094 (cl-letf (((getenv "LINTER_MBX")
5095 (unless (string= "" sql-database
) sql-database
)))
5096 (sql-comint product params
))))
5100 (defcustom sql-vertica-program
"vsql"
5101 "Command to start the Vertica client."
5106 (defcustom sql-vertica-options
'("-P" "pager=off")
5107 "List of additional options for `sql-vertica-program'.
5108 The default value disables the internal pager."
5110 :type
'(repeat string
)
5113 (defcustom sql-vertica-login-params
'(user password database server
)
5114 "List of login parameters needed to connect to Vertica."
5116 :type
'sql-login-params
5119 (defun sql-comint-vertica (product options
)
5120 "Create comint buffer and connect to Vertica."
5123 (and (not (string= "" sql-server
))
5124 (list "-h" sql-server
))
5125 (and (not (string= "" sql-database
))
5126 (list "-d" sql-database
))
5127 (and (not (string= "" sql-password
))
5128 (list "-w" sql-password
))
5129 (and (not (string= "" sql-user
))
5130 (list "-U" sql-user
))
5134 (defun sql-vertica (&optional buffer
)
5135 "Run vsql as an inferior process."
5137 (sql-product-interactive 'vertica buffer
))
5142 ;;; sql.el ends here
5144 ; LocalWords: sql SQL SQLite sqlite Sybase Informix MySQL
5145 ; LocalWords: Postgres SQLServer SQLi