1 ;;; sql.el --- specialized comint.el for SQL interpreters
3 ;; Copyright (C) 1998-2012 Free Software Foundation, Inc.
5 ;; Author: Alex Schroeder <alex@gnu.org>
6 ;; Maintainer: Michael Mauger <mmaug@yahoo.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'.
83 ;;; Requirements for Emacs 19.34:
85 ;; If you are using Emacs 19.34, you will have to get and install
86 ;; the file regexp-opt.el
87 ;; <URL:ftp://ftp.ifi.uio.no/pub/emacs/emacs-20.3/lisp/emacs-lisp/regexp-opt.el>
88 ;; and the custom package
89 ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>.
93 ;; sql-ms now uses osql instead of isql. Osql flushes its error
94 ;; stream more frequently than isql so that error messages are
95 ;; available. There is no prompt and some output still is buffered.
96 ;; This improves the interaction under Emacs but it still is somewhat
99 ;; Quoted identifiers are not supported for highlighting. Most
100 ;; databases support the use of double quoted strings in place of
101 ;; identifiers; ms (Microsoft SQLServer) also supports identifiers
102 ;; enclosed within brackets [].
106 ;; To add support for additional SQL products the following steps
107 ;; must be followed ("xyz" is the name of the product in the examples
110 ;; 1) Add the product to the list of known products.
112 ;; (sql-add-product 'xyz "XyzDB"
113 ;; '(:free-software t))
115 ;; 2) Define font lock settings. All ANSI keywords will be
116 ;; highlighted automatically, so only product specific keywords
117 ;; need to be defined here.
119 ;; (defvar my-sql-mode-xyz-font-lock-keywords
120 ;; '(("\\b\\(red\\|orange\\|yellow\\)\\b"
121 ;; . font-lock-keyword-face))
122 ;; "XyzDB SQL keywords used by font-lock.")
124 ;; (sql-set-product-feature 'xyz
126 ;; 'my-sql-mode-xyz-font-lock-keywords)
128 ;; 3) Define any special syntax characters including comments and
129 ;; identifier characters.
131 ;; (sql-set-product-feature 'xyz
132 ;; :syntax-alist ((?# . "_")))
134 ;; 4) Define the interactive command interpreter for the database
137 ;; (defcustom my-sql-xyz-program "ixyz"
138 ;; "Command to start ixyz by XyzDB."
142 ;; (sql-set-product-feature 'xyz
143 ;; :sqli-program 'my-sql-xyz-program)
144 ;; (sql-set-product-feature 'xyz
145 ;; :prompt-regexp "^xyzdb> ")
146 ;; (sql-set-product-feature 'xyz
149 ;; 5) Define login parameters and command line formatting.
151 ;; (defcustom my-sql-xyz-login-params '(user password server database)
152 ;; "Login parameters to needed to connect to XyzDB."
153 ;; :type 'sql-login-params
156 ;; (sql-set-product-feature 'xyz
157 ;; :sqli-login 'my-sql-xyz-login-params)
159 ;; (defcustom my-sql-xyz-options '("-X" "-Y" "-Z")
160 ;; "List of additional options for `sql-xyz-program'."
161 ;; :type '(repeat string)
164 ;; (sql-set-product-feature 'xyz
165 ;; :sqli-options 'my-sql-xyz-options))
167 ;; (defun my-sql-comint-xyz (product options)
168 ;; "Connect ti XyzDB in a comint buffer."
170 ;; ;; Do something with `sql-user', `sql-password',
171 ;; ;; `sql-database', and `sql-server'.
172 ;; (let ((params options))
173 ;; (if (not (string= "" sql-server))
174 ;; (setq params (append (list "-S" sql-server) params)))
175 ;; (if (not (string= "" sql-database))
176 ;; (setq params (append (list "-D" sql-database) params)))
177 ;; (if (not (string= "" sql-password))
178 ;; (setq params (append (list "-P" sql-password) params)))
179 ;; (if (not (string= "" sql-user))
180 ;; (setq params (append (list "-U" sql-user) params)))
181 ;; (sql-comint product params)))
183 ;; (sql-set-product-feature 'xyz
184 ;; :sqli-comint-func 'my-sql-comint-xyz)
186 ;; 6) Define a convenience function to invoke the SQL interpreter.
188 ;; (defun my-sql-xyz (&optional buffer)
189 ;; "Run ixyz by XyzDB as an inferior process."
191 ;; (sql-product-interactive 'xyz buffer))
195 ;; Improve keyword highlighting for individual products. I have tried
196 ;; to update those database that I use. Feel free to send me updates,
197 ;; or direct me to the reference manuals for your favorite database.
199 ;; When there are no keywords defined, the ANSI keywords are
200 ;; highlighted. ANSI keywords are highlighted even if the keyword is
201 ;; not used for your current product. This should help identify
202 ;; portability concerns.
204 ;; Add different highlighting levels.
206 ;; Add support for listing available tables or the columns in a table.
208 ;;; Thanks to all the people who helped me out:
210 ;; Alex Schroeder <alex@gnu.org> -- the original author
211 ;; Kai Blauberg <kai.blauberg@metla.fi>
212 ;; <ibalaban@dalet.com>
213 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il>
214 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
215 ;; nino <nino@inform.dk>
216 ;; Berend de Boer <berend@pobox.com>
217 ;; Adam Jenkins <adam@thejenkins.org>
218 ;; Michael Mauger <mmaug@yahoo.com> -- improved product support
219 ;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support
220 ;; Harald Maier <maierh@myself.com> -- sql-send-string
221 ;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections;
223 ;; Paul Sleigh <bat@flurf.net> -- MySQL keyword enhancement
224 ;; Andrew Schein <andrew@andrewschein.com> -- sql-port bug
225 ;; Ian Bjorhovde <idbjorh@dataproxy.com> -- db2 escape newlines
226 ;; incorrectly enabled by default
233 ;; Need the following to allow GNU Emacs 19 to compile the file.
235 (require 'regexp-opt
))
238 (eval-when-compile ;; needed in Emacs 19, 20
239 (setq max-specpdl-size
(max max-specpdl-size
2000)))
241 (defun sql-signum (n)
242 "Return 1, 0, or -1 to identify the sign of N."
244 ((not (numberp n
)) nil
)
249 (defvar font-lock-keyword-face
)
250 (defvar font-lock-set-defaults
)
251 (defvar font-lock-string-face
)
253 ;;; Allow customization
256 "Running a SQL interpreter from within Emacs buffers."
261 ;; These four variables will be used as defaults, if set.
263 (defcustom sql-user
""
269 (defcustom sql-password
""
271 If you customize this, the value will be stored in your init
272 file. Since that is a plaintext file, this could be dangerous."
277 (defcustom sql-database
""
283 (defcustom sql-server
""
284 "Default server or host."
289 (defcustom sql-port
0
290 "Default port for connecting to a MySQL or Postgres server."
296 ;; Login parameter type
298 (define-widget 'sql-login-params
'lazy
299 "Widget definition of the login parameters list"
300 ;; FIXME: does not implement :default property for the user,
301 ;; database and server options. Anybody have some guidance on how to
303 :tag
"Login Parameters"
304 :type
'(repeat (choice
307 (choice :tag
"server"
310 (const :format
"" server
)
311 (const :format
"" :file
)
313 (list :tag
"completion"
314 (const :format
"" server
)
315 (const :format
"" :completion
)
317 :match-alternatives
(listp stringp
))))
318 (choice :tag
"database"
321 (const :format
"" database
)
322 (const :format
"" :file
)
324 (list :tag
"completion"
325 (const :format
"" database
)
326 (const :format
"" :completion
)
328 :match-alternatives
(listp stringp
))))
331 ;; SQL Product support
333 (defvar sql-interactive-product nil
334 "Product under `sql-interactive-mode'.")
336 (defvar sql-connection nil
337 "Connection name if interactive session started by `sql-connect'.")
339 (defvar sql-product-alist
342 :font-lock sql-mode-ansi-font-lock-keywords
343 :statement sql-ansi-statement-starters
)
347 :font-lock sql-mode-db2-font-lock-keywords
348 :sqli-program sql-db2-program
349 :sqli-options sql-db2-options
350 :sqli-login sql-db2-login-params
351 :sqli-comint-func sql-comint-db2
352 :prompt-regexp
"^db2 => "
354 :prompt-cont-regexp
"^db2 (cont\.) => "
355 :input-filter sql-escape-newlines-filter
)
359 :font-lock sql-mode-informix-font-lock-keywords
360 :sqli-program sql-informix-program
361 :sqli-options sql-informix-options
362 :sqli-login sql-informix-login-params
363 :sqli-comint-func sql-comint-informix
366 :syntax-alist
((?
{ .
"<") (?
} .
">")))
370 :font-lock sql-mode-ingres-font-lock-keywords
371 :sqli-program sql-ingres-program
372 :sqli-options sql-ingres-options
373 :sqli-login sql-ingres-login-params
374 :sqli-comint-func sql-comint-ingres
375 :prompt-regexp
"^\* "
377 :prompt-cont-regexp
"^\* ")
381 :font-lock sql-mode-interbase-font-lock-keywords
382 :sqli-program sql-interbase-program
383 :sqli-options sql-interbase-options
384 :sqli-login sql-interbase-login-params
385 :sqli-comint-func sql-comint-interbase
386 :prompt-regexp
"^SQL> "
391 :font-lock sql-mode-linter-font-lock-keywords
392 :sqli-program sql-linter-program
393 :sqli-options sql-linter-options
394 :sqli-login sql-linter-login-params
395 :sqli-comint-func sql-comint-linter
396 :prompt-regexp
"^SQL>"
401 :font-lock sql-mode-ms-font-lock-keywords
402 :sqli-program sql-ms-program
403 :sqli-options sql-ms-options
404 :sqli-login sql-ms-login-params
405 :sqli-comint-func sql-comint-ms
406 :prompt-regexp
"^[0-9]*>"
408 :syntax-alist
((?
@ .
"_"))
409 :terminator
("^go" .
"go"))
414 :font-lock sql-mode-mysql-font-lock-keywords
415 :sqli-program sql-mysql-program
416 :sqli-options sql-mysql-options
417 :sqli-login sql-mysql-login-params
418 :sqli-comint-func sql-comint-mysql
419 :list-all
"SHOW TABLES;"
420 :list-table
"DESCRIBE %s;"
421 :prompt-regexp
"^mysql> "
423 :prompt-cont-regexp
"^ -> "
424 :syntax-alist
((?
# .
"< b"))
425 :input-filter sql-remove-tabs-filter
)
429 :font-lock sql-mode-oracle-font-lock-keywords
430 :sqli-program sql-oracle-program
431 :sqli-options sql-oracle-options
432 :sqli-login sql-oracle-login-params
433 :sqli-comint-func sql-comint-oracle
434 :list-all sql-oracle-list-all
435 :list-table sql-oracle-list-table
436 :completion-object sql-oracle-completion-object
437 :prompt-regexp
"^SQL> "
439 :prompt-cont-regexp
"^\\s-*[[:digit:]]+ "
440 :statement sql-oracle-statement-starters
441 :syntax-alist
((?$ .
"_") (?
# .
"_"))
442 :terminator
("\\(^/\\|;\\)$" .
"/")
443 :input-filter sql-placeholders-filter
)
448 :font-lock sql-mode-postgres-font-lock-keywords
449 :sqli-program sql-postgres-program
450 :sqli-options sql-postgres-options
451 :sqli-login sql-postgres-login-params
452 :sqli-comint-func sql-comint-postgres
453 :list-all
("\\d+" .
"\\dS+")
454 :list-table
("\\d+ %s" .
"\\dS+ %s")
455 :completion-object sql-postgres-completion-object
456 :prompt-regexp
"^\\w*=[#>] "
458 :prompt-cont-regexp
"^\\w*[-(][#>] "
459 :input-filter sql-remove-tabs-filter
460 :terminator
("\\(^\\s-*\\\\g$\\|;\\)" .
"\\g"))
464 :font-lock sql-mode-solid-font-lock-keywords
465 :sqli-program sql-solid-program
466 :sqli-options sql-solid-options
467 :sqli-login sql-solid-login-params
468 :sqli-comint-func sql-comint-solid
475 :font-lock sql-mode-sqlite-font-lock-keywords
476 :sqli-program sql-sqlite-program
477 :sqli-options sql-sqlite-options
478 :sqli-login sql-sqlite-login-params
479 :sqli-comint-func sql-comint-sqlite
481 :list-table
".schema %s"
482 :completion-object sql-sqlite-completion-object
483 :prompt-regexp
"^sqlite> "
485 :prompt-cont-regexp
"^ \.\.\.> "
490 :font-lock sql-mode-sybase-font-lock-keywords
491 :sqli-program sql-sybase-program
492 :sqli-options sql-sybase-options
493 :sqli-login sql-sybase-login-params
494 :sqli-comint-func sql-comint-sybase
495 :prompt-regexp
"^SQL> "
497 :syntax-alist
((?
@ .
"_"))
498 :terminator
("^go" .
"go"))
500 "An alist of product specific configuration settings.
502 Without an entry in this list a product will not be properly
503 highlighted and will not support `sql-interactive-mode'.
505 Each element in the list is in the following format:
507 \(PRODUCT FEATURE VALUE ...)
509 where PRODUCT is the appropriate value of `sql-product'. The
510 product name is then followed by FEATURE-VALUE pairs. If a
511 FEATURE is not specified, its VALUE is treated as nil. FEATURE
512 may be any one of the following:
514 :name string containing the displayable name of
517 :free-software is the product Free (as in Freedom) software?
519 :font-lock name of the variable containing the product
520 specific font lock highlighting patterns.
522 :sqli-program name of the variable containing the product
523 specific interactive program name.
525 :sqli-options name of the variable containing the list
526 of product specific options.
528 :sqli-login name of the variable containing the list of
529 login parameters (i.e., user, password,
530 database and server) needed to connect to
533 :sqli-comint-func name of a function which accepts no
534 parameters that will use the values of
535 `sql-user', `sql-password',
536 `sql-database', `sql-server' and
537 `sql-port' to open a comint buffer and
538 connect to the database. Do product
539 specific configuration of comint in this
542 :list-all Command string or function which produces
543 a listing of all objects in the database.
544 If it's a cons cell, then the car
545 produces the standard list of objects and
546 the cdr produces an enhanced list of
547 objects. What \"enhanced\" means is
548 dependent on the SQL product and may not
549 exist. In general though, the
550 \"enhanced\" list should include visible
551 objects from other schemas.
553 :list-table Command string or function which produces
554 a detailed listing of a specific database
555 table. If its a cons cell, then the car
556 produces the standard list and the cdr
557 produces an enhanced list.
559 :completion-object A function that returns a list of
560 objects. Called with a single
561 parameter--if nil then list objects
562 accessible in the current schema, if
563 not-nil it is the name of a schema whose
564 objects should be listed.
566 :completion-column A function that returns a list of
567 columns. Called with a single
568 parameter--if nil then list objects
569 accessible in the current schema, if
570 not-nil it is the name of a schema whose
571 objects should be listed.
573 :prompt-regexp regular expression string that matches
574 the prompt issued by the product
577 :prompt-length length of the prompt on the line.
579 :prompt-cont-regexp regular expression string that matches
580 the continuation prompt issued by the
583 :input-filter function which can filter strings sent to
584 the command interpreter. It is also used
585 by the `sql-send-string',
586 `sql-send-region', `sql-send-paragraph'
587 and `sql-send-buffer' functions. The
588 function is passed the string sent to the
589 command interpreter and must return the
590 filtered string. May also be a list of
593 :statement name of a variable containing a regexp that
594 matches the beginning of SQL statements.
596 :terminator the terminator to be sent after a
597 `sql-send-string', `sql-send-region',
598 `sql-send-paragraph' and
599 `sql-send-buffer' command. May be the
600 literal string or a cons of a regexp to
601 match an existing terminator in the
602 string and the terminator to be used if
603 its absent. By default \";\".
605 :syntax-alist alist of syntax table entries to enable
606 special character treatment by font-lock
609 Other features can be stored but they will be ignored. However,
610 you can develop new functionality which is product independent by
611 using `sql-get-product-feature' to lookup the product specific
614 (defvar sql-indirect-features
615 '(:font-lock
:sqli-program
:sqli-options
:sqli-login
:statement
))
617 (defcustom sql-connection-alist nil
618 "An alist of connection parameters for interacting with a SQL product.
619 Each element of the alist is as follows:
621 \(CONNECTION \(SQL-VARIABLE VALUE) ...)
623 Where CONNECTION is a symbol identifying the connection, SQL-VARIABLE
624 is the symbol name of a SQL mode variable, and VALUE is the value to
625 be assigned to the variable. The most common SQL-VARIABLE settings
626 associated with a connection are: `sql-product', `sql-user',
627 `sql-password', `sql-port', `sql-server', and `sql-database'.
629 If a SQL-VARIABLE is part of the connection, it will not be
630 prompted for during login. The command `sql-connect' starts a
631 predefined SQLi session using the parameters from this list.
632 Connections defined here appear in the submenu SQL->Start... for
633 making new SQLi sessions."
634 :type
`(alist :key-type
(string :tag
"Connection")
637 (group (const :tag
"Product" sql-product
)
639 ,@(mapcar (lambda (prod-info)
641 ,(or (plist-get (cdr prod-info
) :name
)
642 (capitalize (symbol-name (car prod-info
))))
643 (quote ,(car prod-info
))))
645 (group (const :tag
"Username" sql-user
) string
)
646 (group (const :tag
"Password" sql-password
) string
)
647 (group (const :tag
"Server" sql-server
) string
)
648 (group (const :tag
"Database" sql-database
) string
)
649 (group (const :tag
"Port" sql-port
) integer
)
652 (symbol :tag
" Variable Symbol")
653 (sexp :tag
"Value Expression")))))
657 (defcustom sql-product
'ansi
658 "Select the SQL database product used so that buffers can be
659 highlighted properly when you open them."
661 ,@(mapcar (lambda (prod-info)
663 ,(or (plist-get (cdr prod-info
) :name
)
664 (capitalize (symbol-name (car prod-info
))))
669 (defvaralias 'sql-dialect
'sql-product
)
671 ;; misc customization of sql.el behavior
673 (defcustom sql-electric-stuff nil
674 "Treat some input as electric.
675 If set to the symbol `semicolon', then hitting `;' will send current
676 input in the SQLi buffer to the process.
677 If set to the symbol `go', then hitting `go' on a line by itself will
678 send current input in the SQLi buffer to the process.
679 If set to nil, then you must use \\[comint-send-input] in order to send
680 current input in the SQLi buffer to the process."
681 :type
'(choice (const :tag
"Nothing" nil
)
682 (const :tag
"The semicolon `;'" semicolon
)
683 (const :tag
"The string `go' by itself" go
))
687 (defcustom sql-send-terminator nil
688 "When non-nil, add a terminator to text sent to the SQL interpreter.
690 When text is sent to the SQL interpreter (via `sql-send-string',
691 `sql-send-region', `sql-send-paragraph' or `sql-send-buffer'), a
692 command terminator can be automatically sent as well. The
693 terminator is not sent, if the string sent already ends with the
696 If this value is t, then the default command terminator for the
697 SQL interpreter is sent. If this value is a string, then the
700 If the value is a cons cell of the form (PAT . TERM), then PAT is
701 a regexp used to match the terminator in the string and TERM is
702 the terminator to be sent. This form is useful if the SQL
703 interpreter has more than one way of submitting a SQL command.
704 The PAT regexp can match any of them, and TERM is the way we do
707 :type
'(choice (const :tag
"No Terminator" nil
)
708 (const :tag
"Default Terminator" t
)
709 (string :tag
"Terminator String")
710 (cons :tag
"Terminator Pattern and String"
711 (string :tag
"Terminator Pattern")
712 (string :tag
"Terminator String")))
716 (defvar sql-contains-names nil
717 "When non-nil, the current buffer contains database names.
719 Globally should be set to nil; it will be non-nil in `sql-mode',
720 `sql-interactive-mode' and list all buffers.")
723 (defcustom sql-pop-to-buffer-after-send-region nil
724 "When non-nil, pop to the buffer SQL statements are sent to.
726 After a call to `sql-sent-string', `sql-send-region',
727 `sql-send-paragraph' or `sql-send-buffer', the window is split
728 and the SQLi buffer is shown. If this variable is not nil, that
729 buffer's window will be selected by calling `pop-to-buffer'. If
730 this variable is nil, that buffer is shown using
735 ;; imenu support for sql-mode.
737 (defvar sql-imenu-generic-expression
738 ;; Items are in reverse order because they are rendered in reverse.
739 '(("Rules/Defaults" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*\\(?:rule\\|default\\)\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\s-+\\(\\w+\\)" 1)
740 ("Sequences" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*sequence\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\w+\\)" 1)
741 ("Triggers" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*trigger\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\w+\\)" 1)
742 ("Functions" "^\\s-*\\(?:create\\s-+\\(?:\\w+\\s-+\\)*\\)?function\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\w+\\)" 1)
743 ("Procedures" "^\\s-*\\(?:create\\s-+\\(?:\\w+\\s-+\\)*\\)?proc\\(?:edure\\)?\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\w+\\)" 1)
744 ("Packages" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*package\\s-+\\(?:body\\s-+\\)?\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\w+\\)" 1)
745 ("Types" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*type\\s-+\\(?:body\\s-+\\)?\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\w+\\)" 1)
746 ("Indexes" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*index\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\w+\\)" 1)
747 ("Tables/Views" "^\\s-*create\\s-+\\(?:\\w+\\s-+\\)*\\(?:table\\|view\\)\\s-+\\(?:if\\s-+not\\s-+exists\\s-+\\)?\\(\\w+\\)" 1))
748 "Define interesting points in the SQL buffer for `imenu'.
750 This is used to set `imenu-generic-expression' when SQL mode is
751 entered. Subsequent changes to `sql-imenu-generic-expression' will
752 not affect existing SQL buffers because imenu-generic-expression is
757 (defcustom sql-input-ring-file-name nil
758 "If non-nil, name of the file to read/write input history.
760 You have to set this variable if you want the history of your commands
761 saved from one Emacs session to the next. If this variable is set,
762 exiting the SQL interpreter in an SQLi buffer will write the input
763 history to the specified file. Starting a new process in a SQLi buffer
764 will read the input history from the specified file.
766 This is used to initialize `comint-input-ring-file-name'.
768 Note that the size of the input history is determined by the variable
769 `comint-input-ring-size'."
770 :type
'(choice (const :tag
"none" nil
)
774 (defcustom sql-input-ring-separator
"\n--\n"
775 "Separator between commands in the history file.
777 If set to \"\\n\", each line in the history file will be interpreted as
778 one command. Multi-line commands are split into several commands when
779 the input ring is initialized from a history file.
781 This variable used to initialize `comint-input-ring-separator'.
782 `comint-input-ring-separator' is part of Emacs 21; if your Emacs
783 does not have it, setting `sql-input-ring-separator' will have no
784 effect. In that case multiline commands will be split into several
785 commands when the input history is read, as if you had set
786 `sql-input-ring-separator' to \"\\n\"."
792 (defcustom sql-interactive-mode-hook
'()
793 "Hook for customizing `sql-interactive-mode'."
797 (defcustom sql-mode-hook
'()
798 "Hook for customizing `sql-mode'."
802 (defcustom sql-set-sqli-hook
'()
803 "Hook for reacting to changes of `sql-buffer'.
805 This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
810 (defcustom sql-login-hook
'()
811 "Hook for interacting with a buffer in `sql-interactive-mode'.
813 This hook is invoked in a buffer once it is ready to accept input
819 ;; Customization for ANSI
821 (defcustom sql-ansi-statement-starters
(regexp-opt '(
822 "create" "alter" "drop"
823 "select" "insert" "update" "delete" "merge"
826 "Regexp of keywords that start SQL commands
828 All products share this list; products should define a regexp to
829 identify additional keywords in a variable defined by
830 the :statement feature."
835 ;; Customization for Oracle
837 (defcustom sql-oracle-program
"sqlplus"
838 "Command to start sqlplus by Oracle.
840 Starts `sql-interactive-mode' after doing some setup.
842 On Windows, \"sqlplus\" usually starts the sqlplus \"GUI\". In order
843 to start the sqlplus console, use \"plus33\" or something similar.
844 You will find the file in your Orant\\bin directory."
848 (defcustom sql-oracle-options nil
849 "List of additional options for `sql-oracle-program'."
850 :type
'(repeat string
)
854 (defcustom sql-oracle-login-params
'(user password database
)
855 "List of login parameters needed to connect to Oracle."
856 :type
'sql-login-params
860 (defcustom sql-oracle-statement-starters
861 (regexp-opt '("declare" "begin" "with"))
862 "Additional statement starting keywords in Oracle."
867 (defcustom sql-oracle-scan-on t
868 "Non-nil if placeholders should be replaced in Oracle SQLi.
870 When non-nil, Emacs will scan text sent to sqlplus and prompt
871 for replacement text for & placeholders as sqlplus does. This
872 is needed on Windows where SQL*Plus output is buffered and the
873 prompts are not shown until after the text is entered.
875 You need to issue the following command in SQL*Plus to be safe:
879 In older versions of SQL*Plus, this was the SET SCAN OFF command."
884 (defcustom sql-db2-escape-newlines nil
885 "Non-nil if newlines should be escaped by a backslash in DB2 SQLi.
887 When non-nil, Emacs will automatically insert a space and
888 backslash prior to every newline in multi-line SQL statements as
889 they are submitted to an interactive DB2 session."
894 ;; Customization for SQLite
896 (defcustom sql-sqlite-program
(or (executable-find "sqlite3")
897 (executable-find "sqlite")
899 "Command to start SQLite.
901 Starts `sql-interactive-mode' after doing some setup."
905 (defcustom sql-sqlite-options nil
906 "List of additional options for `sql-sqlite-program'."
907 :type
'(repeat string
)
911 (defcustom sql-sqlite-login-params
'((database :file
".*\\.\\(db\\|sqlite[23]?\\)"))
912 "List of login parameters needed to connect to SQLite."
913 :type
'sql-login-params
917 ;; Customization for MySQL
919 (defcustom sql-mysql-program
"mysql"
920 "Command to start mysql by TcX.
922 Starts `sql-interactive-mode' after doing some setup."
926 (defcustom sql-mysql-options nil
927 "List of additional options for `sql-mysql-program'.
928 The following list of options is reported to make things work
929 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
930 :type
'(repeat string
)
934 (defcustom sql-mysql-login-params
'(user password database server
)
935 "List of login parameters needed to connect to MySQL."
936 :type
'sql-login-params
940 ;; Customization for Solid
942 (defcustom sql-solid-program
"solsql"
943 "Command to start SOLID SQL Editor.
945 Starts `sql-interactive-mode' after doing some setup."
949 (defcustom sql-solid-login-params
'(user password server
)
950 "List of login parameters needed to connect to Solid."
951 :type
'sql-login-params
955 ;; Customization for Sybase
957 (defcustom sql-sybase-program
"isql"
958 "Command to start isql by Sybase.
960 Starts `sql-interactive-mode' after doing some setup."
964 (defcustom sql-sybase-options nil
965 "List of additional options for `sql-sybase-program'.
966 Some versions of isql might require the -n option in order to work."
967 :type
'(repeat string
)
971 (defcustom sql-sybase-login-params
'(server user password database
)
972 "List of login parameters needed to connect to Sybase."
973 :type
'sql-login-params
977 ;; Customization for Informix
979 (defcustom sql-informix-program
"dbaccess"
980 "Command to start dbaccess by Informix.
982 Starts `sql-interactive-mode' after doing some setup."
986 (defcustom sql-informix-login-params
'(database)
987 "List of login parameters needed to connect to Informix."
988 :type
'sql-login-params
992 ;; Customization for Ingres
994 (defcustom sql-ingres-program
"sql"
995 "Command to start sql by Ingres.
997 Starts `sql-interactive-mode' after doing some setup."
1001 (defcustom sql-ingres-login-params
'(database)
1002 "List of login parameters needed to connect to Ingres."
1003 :type
'sql-login-params
1007 ;; Customization for Microsoft
1009 (defcustom sql-ms-program
"osql"
1010 "Command to start osql by Microsoft.
1012 Starts `sql-interactive-mode' after doing some setup."
1016 (defcustom sql-ms-options
'("-w" "300" "-n")
1017 ;; -w is the linesize
1018 "List of additional options for `sql-ms-program'."
1019 :type
'(repeat string
)
1023 (defcustom sql-ms-login-params
'(user password server database
)
1024 "List of login parameters needed to connect to Microsoft."
1025 :type
'sql-login-params
1029 ;; Customization for Postgres
1031 (defcustom sql-postgres-program
"psql"
1032 "Command to start psql by Postgres.
1034 Starts `sql-interactive-mode' after doing some setup."
1038 (defcustom sql-postgres-options
'("-P" "pager=off")
1039 "List of additional options for `sql-postgres-program'.
1040 The default setting includes the -P option which breaks older versions
1041 of the psql client (such as version 6.5.3). The -P option is equivalent
1042 to the --pset option. If you want the psql to prompt you for a user
1043 name, add the string \"-u\" to the list of options. If you want to
1044 provide a user name on the command line (newer versions such as 7.1),
1045 add your name with a \"-U\" prefix (such as \"-Umark\") to the list."
1046 :type
'(repeat string
)
1050 (defcustom sql-postgres-login-params
`((user :default
,(user-login-name))
1051 (database :default
,(user-login-name))
1053 "List of login parameters needed to connect to Postgres."
1054 :type
'sql-login-params
1058 ;; Customization for Interbase
1060 (defcustom sql-interbase-program
"isql"
1061 "Command to start isql by Interbase.
1063 Starts `sql-interactive-mode' after doing some setup."
1067 (defcustom sql-interbase-options nil
1068 "List of additional options for `sql-interbase-program'."
1069 :type
'(repeat string
)
1073 (defcustom sql-interbase-login-params
'(user password database
)
1074 "List of login parameters needed to connect to Interbase."
1075 :type
'sql-login-params
1079 ;; Customization for DB2
1081 (defcustom sql-db2-program
"db2"
1082 "Command to start db2 by IBM.
1084 Starts `sql-interactive-mode' after doing some setup."
1088 (defcustom sql-db2-options nil
1089 "List of additional options for `sql-db2-program'."
1090 :type
'(repeat string
)
1094 (defcustom sql-db2-login-params nil
1095 "List of login parameters needed to connect to DB2."
1096 :type
'sql-login-params
1100 ;; Customization for Linter
1102 (defcustom sql-linter-program
"inl"
1103 "Command to start inl by RELEX.
1105 Starts `sql-interactive-mode' after doing some setup."
1109 (defcustom sql-linter-options nil
1110 "List of additional options for `sql-linter-program'."
1111 :type
'(repeat string
)
1115 (defcustom sql-linter-login-params
'(user password database server
)
1116 "Login parameters to needed to connect to Linter."
1117 :type
'sql-login-params
1123 ;;; Variables which do not need customization
1125 (defvar sql-user-history nil
1126 "History of usernames used.")
1128 (defvar sql-database-history nil
1129 "History of databases used.")
1131 (defvar sql-server-history nil
1132 "History of servers used.")
1134 ;; Passwords are not kept in a history.
1136 (defvar sql-product-history nil
1137 "History of products used.")
1139 (defvar sql-connection-history nil
1140 "History of connections used.")
1142 (defvar sql-buffer nil
1143 "Current SQLi buffer.
1145 The global value of `sql-buffer' is the name of the latest SQLi buffer
1146 created. Any SQL buffer created will make a local copy of this value.
1147 See `sql-interactive-mode' for more on multiple sessions. If you want
1148 to change the SQLi buffer a SQL mode sends its SQL strings to, change
1149 the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
1151 (defvar sql-prompt-regexp nil
1152 "Prompt used to initialize `comint-prompt-regexp'.
1154 You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.")
1156 (defvar sql-prompt-length
0
1157 "Prompt used to set `left-margin' in `sql-interactive-mode'.
1159 You can change `sql-prompt-length' on `sql-interactive-mode-hook'.")
1161 (defvar sql-prompt-cont-regexp nil
1162 "Prompt pattern of statement continuation prompts.")
1164 (defvar sql-alternate-buffer-name nil
1165 "Buffer-local string used to possibly rename the SQLi buffer.
1167 Used by `sql-rename-buffer'.")
1169 (defun sql-buffer-live-p (buffer &optional product connection
)
1170 "Returns non-nil if the process associated with buffer is live.
1172 BUFFER can be a buffer object or a buffer name. The buffer must
1173 be a live buffer, have an running process attached to it, be in
1174 `sql-interactive-mode', and, if PRODUCT or CONNECTION are
1175 specified, it's `sql-product' or `sql-connection' must match."
1178 (setq buffer
(get-buffer buffer
))
1180 (buffer-live-p buffer
)
1181 (get-buffer-process buffer
)
1182 (comint-check-proc buffer
)
1183 (with-current-buffer buffer
1184 (and (derived-mode-p 'sql-interactive-mode
)
1186 (eq product sql-product
))
1187 (or (not connection
)
1188 (eq connection sql-connection
)))))))
1190 ;; Keymap for sql-interactive-mode.
1192 (defvar sql-interactive-mode-map
1193 (let ((map (make-sparse-keymap)))
1194 (if (fboundp 'set-keymap-parent
)
1195 (set-keymap-parent map comint-mode-map
); Emacs
1196 (if (fboundp 'set-keymap-parents
)
1197 (set-keymap-parents map
(list comint-mode-map
)))); XEmacs
1198 (if (fboundp 'set-keymap-name
)
1199 (set-keymap-name map
'sql-interactive-mode-map
)); XEmacs
1200 (define-key map
(kbd "C-j") 'sql-accumulate-and-indent
)
1201 (define-key map
(kbd "C-c C-w") 'sql-copy-column
)
1202 (define-key map
(kbd "O") 'sql-magic-go
)
1203 (define-key map
(kbd "o") 'sql-magic-go
)
1204 (define-key map
(kbd ";") 'sql-magic-semicolon
)
1205 (define-key map
(kbd "C-c C-l a") 'sql-list-all
)
1206 (define-key map
(kbd "C-c C-l t") 'sql-list-table
)
1208 "Mode map used for `sql-interactive-mode'.
1209 Based on `comint-mode-map'.")
1211 ;; Keymap for sql-mode.
1213 (defvar sql-mode-map
1214 (let ((map (make-sparse-keymap)))
1215 (define-key map
(kbd "C-c C-c") 'sql-send-paragraph
)
1216 (define-key map
(kbd "C-c C-r") 'sql-send-region
)
1217 (define-key map
(kbd "C-c C-s") 'sql-send-string
)
1218 (define-key map
(kbd "C-c C-b") 'sql-send-buffer
)
1219 (define-key map
(kbd "C-c C-i") 'sql-product-interactive
)
1220 (define-key map
(kbd "C-c C-l a") 'sql-list-all
)
1221 (define-key map
(kbd "C-c C-l t") 'sql-list-table
)
1222 (define-key map
[remap beginning-of-defun
] 'sql-beginning-of-statement
)
1223 (define-key map
[remap end-of-defun
] 'sql-end-of-statement
)
1225 "Mode map used for `sql-mode'.")
1227 ;; easy menu for sql-mode.
1230 sql-mode-menu sql-mode-map
1231 "Menu for `sql-mode'."
1233 ["Send Paragraph" sql-send-paragraph
(sql-buffer-live-p sql-buffer
)]
1234 ["Send Region" sql-send-region
(and mark-active
1235 (sql-buffer-live-p sql-buffer
))]
1236 ["Send Buffer" sql-send-buffer
(sql-buffer-live-p sql-buffer
)]
1237 ["Send String" sql-send-string
(sql-buffer-live-p sql-buffer
)]
1239 ["List all objects" sql-list-all
(and (sql-buffer-live-p sql-buffer
)
1240 (sql-get-product-feature sql-product
:list-all
))]
1241 ["List table details" sql-list-table
(and (sql-buffer-live-p sql-buffer
)
1242 (sql-get-product-feature sql-product
:list-table
))]
1244 ["Start SQLi session" sql-product-interactive
1245 :visible
(not sql-connection-alist
)
1246 :enable
(sql-get-product-feature sql-product
:sqli-comint-func
)]
1248 :visible sql-connection-alist
1249 :filter sql-connection-menu-filter
1251 ["New SQLi Session" sql-product-interactive
(sql-get-product-feature sql-product
:sqli-comint-func
)])
1253 :visible sql-connection-alist
]
1254 ["Show SQLi buffer" sql-show-sqli-buffer t
]
1255 ["Set SQLi buffer" sql-set-sqli-buffer t
]
1256 ["Pop to SQLi buffer after send"
1257 sql-toggle-pop-to-buffer-after-send-region
1259 :selected sql-pop-to-buffer-after-send-region
]
1262 ,@(mapcar (lambda (prod-info)
1263 (let* ((prod (pop prod-info
))
1264 (name (or (plist-get prod-info
:name
)
1265 (capitalize (symbol-name prod
))))
1266 (cmd (intern (format "sql-highlight-%s-keywords" prod
))))
1267 (fset cmd
`(lambda () ,(format "Highlight %s SQL keywords." name
)
1269 (sql-set-product ',prod
)))
1272 :selected
`(eq sql-product
',prod
))))
1273 sql-product-alist
))))
1275 ;; easy menu for sql-interactive-mode.
1278 sql-interactive-mode-menu sql-interactive-mode-map
1279 "Menu for `sql-interactive-mode'."
1281 ["Rename Buffer" sql-rename-buffer t
]
1282 ["Save Connection" sql-save-connection
(not sql-connection
)]
1284 ["List all objects" sql-list-all
(sql-get-product-feature sql-product
:list-all
)]
1285 ["List table details" sql-list-table
(sql-get-product-feature sql-product
:list-table
)]))
1287 ;; Abbreviations -- if you want more of them, define them in your init
1288 ;; file. Abbrevs have to be enabled in your init file, too.
1290 (defvar sql-mode-abbrev-table nil
1291 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")
1292 (unless sql-mode-abbrev-table
1293 (define-abbrev-table 'sql-mode-abbrev-table nil
))
1296 ;; In Emacs 22+, provide SYSTEM-FLAG to define-abbrev.
1298 (let ((name (car abbrev
))
1299 (expansion (cdr abbrev
)))
1301 (define-abbrev sql-mode-abbrev-table name expansion nil
0 t
)
1303 (define-abbrev sql-mode-abbrev-table name expansion
)))))
1304 '(("ins" .
"insert")
1308 ("proc" .
"procedure")
1309 ("func" .
"function")
1314 (defvar sql-mode-syntax-table
1315 (let ((table (make-syntax-table)))
1316 ;; C-style comments /**/ (see elisp manual "Syntax Flags"))
1317 (modify-syntax-entry ?
/ ". 14" table
)
1318 (modify-syntax-entry ?
* ". 23" table
)
1319 ;; double-dash starts comments
1320 (modify-syntax-entry ?-
". 12b" table
)
1321 ;; newline and formfeed end comments
1322 (modify-syntax-entry ?
\n "> b" table
)
1323 (modify-syntax-entry ?
\f "> b" table
)
1324 ;; single quotes (') delimit strings
1325 (modify-syntax-entry ?
' "\"" table
)
1326 ;; double quotes (") don't delimit strings
1327 (modify-syntax-entry ?
\" "." table
)
1328 ;; Make these all punctuation
1329 (mapc (lambda (c) (modify-syntax-entry c
"." table
))
1330 (string-to-list "!#$%&+,.:;<=>?@\\|"))
1332 "Syntax table used in `sql-mode' and `sql-interactive-mode'.")
1334 ;; Font lock support
1336 (defvar sql-mode-font-lock-object-name
1338 (list (concat "^\\s-*\\(?:create\\|drop\\|alter\\)\\s-+" ;; lead off with CREATE, DROP or ALTER
1339 "\\(?:\\w+\\s-+\\)*" ;; optional intervening keywords
1340 "\\(?:table\\|view\\|\\(?:package\\|type\\)\\(?:\\s-+body\\)?\\|proc\\(?:edure\\)?"
1341 "\\|function\\|trigger\\|sequence\\|rule\\|default\\)\\s-+"
1342 "\\(?:if\\s-+not\\s-+exists\\s-+\\)?" ;; IF NOT EXISTS
1344 1 'font-lock-function-name-face
))
1346 "Pattern to match the names of top-level objects.
1348 The pattern matches the name in a CREATE, DROP or ALTER
1349 statement. The format of variable should be a valid
1350 `font-lock-keywords' entry.")
1352 ;; While there are international and American standards for SQL, they
1353 ;; are not followed closely, and most vendors offer significant
1354 ;; capabilities beyond those defined in the standard specifications.
1356 ;; SQL mode provides support for highlighting based on the product. In
1357 ;; addition to highlighting the product keywords, any ANSI keywords not
1358 ;; used by the product are also highlighted. This will help identify
1359 ;; keywords that could be restricted in future versions of the product
1360 ;; or might be a problem if ported to another product.
1362 ;; To reduce the complexity and size of the regular expressions
1363 ;; generated to match keywords, ANSI keywords are filtered out of
1364 ;; product keywords if they are equivalent. To do this, we define a
1365 ;; function `sql-font-lock-keywords-builder' that removes any keywords
1366 ;; that are matched by the ANSI patterns and results in the same face
1367 ;; being applied. For this to work properly, we must play some games
1368 ;; with the execution and compile time behavior. This code is a
1369 ;; little tricky but works properly.
1371 ;; When defining the keywords for individual products you should
1372 ;; include all of the keywords that you want matched. The filtering
1373 ;; against the ANSI keywords will be automatic if you use the
1374 ;; `sql-font-lock-keywords-builder' function and follow the
1375 ;; implementation pattern used for the other products in this file.
1378 (defvar sql-mode-ansi-font-lock-keywords
)
1379 (setq sql-mode-ansi-font-lock-keywords nil
))
1382 (defun sql-font-lock-keywords-builder (face boundaries
&rest keywords
)
1383 "Generation of regexp matching any one of KEYWORDS."
1385 (let ((bdy (or boundaries
'("\\b" .
"\\b")))
1388 ;; Remove keywords that are defined in ANSI
1390 ;; (dolist (k keywords)
1392 ;; (dolist (a sql-mode-ansi-font-lock-keywords)
1393 ;; (when (and (eq face (cdr a))
1394 ;; (eq (string-match (car a) k 0) 0)
1395 ;; (eq (match-end 0) (length k)))
1396 ;; (setq kwd (delq k kwd))
1397 ;; (throw 'next nil)))))
1399 ;; Create a properly formed font-lock-keywords item
1400 (cons (concat (car bdy
)
1405 (defun sql-regexp-abbrev (keyword)
1406 (let ((brk (string-match "[~]" keyword
))
1407 (len (length keyword
))
1412 (setq re
(substring keyword
0 brk
)
1416 (setq re
(concat re sep
(substring keyword brk i
))
1419 (concat re
"\\)?"))))
1421 (defun sql-regexp-abbrev-list (&rest keyw-list
)
1425 (setq re
(concat re sep
(sql-regexp-abbrev (car keyw-list
)))
1427 keyw-list
(cdr keyw-list
)))
1428 (concat re
"\\)\\>"))))
1431 (setq sql-mode-ansi-font-lock-keywords
1433 ;; ANSI Non Reserved keywords
1434 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1435 "ada" "asensitive" "assignment" "asymmetric" "atomic" "between"
1436 "bitvar" "called" "catalog_name" "chain" "character_set_catalog"
1437 "character_set_name" "character_set_schema" "checked" "class_origin"
1438 "cobol" "collation_catalog" "collation_name" "collation_schema"
1439 "column_name" "command_function" "command_function_code" "committed"
1440 "condition_number" "connection_name" "constraint_catalog"
1441 "constraint_name" "constraint_schema" "contains" "cursor_name"
1442 "datetime_interval_code" "datetime_interval_precision" "defined"
1443 "definer" "dispatch" "dynamic_function" "dynamic_function_code"
1444 "existing" "exists" "final" "fortran" "generated" "granted"
1445 "hierarchy" "hold" "implementation" "infix" "insensitive" "instance"
1446 "instantiable" "invoker" "key_member" "key_type" "length" "m"
1447 "message_length" "message_octet_length" "message_text" "method" "more"
1448 "mumps" "name" "nullable" "number" "options" "overlaps" "overriding"
1449 "parameter_mode" "parameter_name" "parameter_ordinal_position"
1450 "parameter_specific_catalog" "parameter_specific_name"
1451 "parameter_specific_schema" "pascal" "pli" "position" "repeatable"
1452 "returned_length" "returned_octet_length" "returned_sqlstate"
1453 "routine_catalog" "routine_name" "routine_schema" "row_count" "scale"
1454 "schema_name" "security" "self" "sensitive" "serializable"
1455 "server_name" "similar" "simple" "source" "specific_name" "style"
1456 "subclass_origin" "sublist" "symmetric" "system" "table_name"
1457 "transaction_active" "transactions_committed"
1458 "transactions_rolled_back" "transform" "transforms" "trigger_catalog"
1459 "trigger_name" "trigger_schema" "type" "uncommitted" "unnamed"
1460 "user_defined_type_catalog" "user_defined_type_name"
1461 "user_defined_type_schema"
1464 ;; ANSI Reserved keywords
1465 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1466 "absolute" "action" "add" "admin" "after" "aggregate" "alias" "all"
1467 "allocate" "alter" "and" "any" "are" "as" "asc" "assertion" "at"
1468 "authorization" "before" "begin" "both" "breadth" "by" "call"
1469 "cascade" "cascaded" "case" "catalog" "check" "class" "close"
1470 "collate" "collation" "column" "commit" "completion" "connect"
1471 "connection" "constraint" "constraints" "constructor" "continue"
1472 "corresponding" "create" "cross" "cube" "current" "cursor" "cycle"
1473 "data" "day" "deallocate" "declare" "default" "deferrable" "deferred"
1474 "delete" "depth" "deref" "desc" "describe" "descriptor" "destroy"
1475 "destructor" "deterministic" "diagnostics" "dictionary" "disconnect"
1476 "distinct" "domain" "drop" "dynamic" "each" "else" "end" "equals"
1477 "escape" "every" "except" "exception" "exec" "execute" "external"
1478 "false" "fetch" "first" "for" "foreign" "found" "free" "from" "full"
1479 "function" "general" "get" "global" "go" "goto" "grant" "group"
1480 "grouping" "having" "host" "hour" "identity" "ignore" "immediate" "in"
1481 "indicator" "initialize" "initially" "inner" "inout" "input" "insert"
1482 "intersect" "into" "is" "isolation" "iterate" "join" "key" "language"
1483 "last" "lateral" "leading" "left" "less" "level" "like" "limit"
1484 "local" "locator" "map" "match" "minute" "modifies" "modify" "module"
1485 "month" "names" "natural" "new" "next" "no" "none" "not" "null" "of"
1486 "off" "old" "on" "only" "open" "operation" "option" "or" "order"
1487 "ordinality" "out" "outer" "output" "pad" "parameter" "parameters"
1488 "partial" "path" "postfix" "prefix" "preorder" "prepare" "preserve"
1489 "primary" "prior" "privileges" "procedure" "public" "read" "reads"
1490 "recursive" "references" "referencing" "relative" "restrict" "result"
1491 "return" "returns" "revoke" "right" "role" "rollback" "rollup"
1492 "routine" "rows" "savepoint" "schema" "scroll" "search" "second"
1493 "section" "select" "sequence" "session" "set" "sets" "size" "some"
1494 "space" "specific" "specifictype" "sql" "sqlexception" "sqlstate"
1495 "sqlwarning" "start" "state" "statement" "static" "structure" "table"
1496 "temporary" "terminate" "than" "then" "timezone_hour"
1497 "timezone_minute" "to" "trailing" "transaction" "translation"
1498 "trigger" "true" "under" "union" "unique" "unknown" "unnest" "update"
1499 "usage" "using" "value" "values" "variable" "view" "when" "whenever"
1500 "where" "with" "without" "work" "write" "year"
1504 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1505 "abs" "avg" "bit_length" "cardinality" "cast" "char_length"
1506 "character_length" "coalesce" "convert" "count" "current_date"
1507 "current_path" "current_role" "current_time" "current_timestamp"
1508 "current_user" "extract" "localtime" "localtimestamp" "lower" "max"
1509 "min" "mod" "nullif" "octet_length" "overlay" "placing" "session_user"
1510 "substring" "sum" "system_user" "translate" "treat" "trim" "upper"
1515 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1516 "array" "binary" "bit" "blob" "boolean" "char" "character" "clob"
1517 "date" "dec" "decimal" "double" "float" "int" "integer" "interval"
1518 "large" "national" "nchar" "nclob" "numeric" "object" "precision"
1519 "real" "ref" "row" "scope" "smallint" "time" "timestamp" "varchar"
1523 (defvar sql-mode-ansi-font-lock-keywords
1524 (eval-when-compile sql-mode-ansi-font-lock-keywords
)
1525 "ANSI SQL keywords used by font-lock.
1527 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1528 regular expressions are created during compilation by calling the
1529 function `regexp-opt'. Therefore, take a look at the source before
1530 you define your own `sql-mode-ansi-font-lock-keywords'. You may want
1531 to add functions and PL/SQL keywords.")
1533 (defun sql-oracle-show-reserved-words ()
1534 ;; This function is for use by the maintainer of SQL.EL only.
1536 (if (or (and (not (derived-mode-p 'sql-mode
))
1537 (not (derived-mode-p 'sql-interactive-mode
)))
1539 (not (eq sql-product
'oracle
)))
1540 (error "Not an Oracle buffer")
1542 (let ((b "*RESERVED WORDS*"))
1543 (sql-execute sql-buffer b
1546 ", reserved AS \"Res\" "
1547 ", res_type AS \"Type\" "
1548 ", res_attr AS \"Attr\" "
1549 ", res_semi AS \"Semi\" "
1550 ", duplicate AS \"Dup\" "
1551 "FROM V$RESERVED_WORDS "
1553 "AND SUBSTR(keyword, 1, 1) BETWEEN 'A' AND 'Z' "
1554 "ORDER BY 2 DESC, 3 DESC, 4 DESC, 5 DESC, 6 DESC, 1;")
1556 (with-current-buffer b
1557 (set (make-local-variable 'sql-product
) 'oracle
)
1558 (sql-product-font-lock t nil
)
1559 (font-lock-mode +1)))))
1561 (defvar sql-mode-oracle-font-lock-keywords
1564 ;; Oracle SQL*Plus Commands
1565 ;; Only recognized in they start in column 1 and the
1566 ;; abbreviation is followed by a space or the end of line.
1569 (list (concat "^" (sql-regexp-abbrev "rem~ark") "\\(?:\\s-.*\\)?$")
1570 0 'font-lock-comment-face t
)
1575 (sql-regexp-abbrev-list
1576 "[@]\\{1,2\\}" "acc~ept" "a~ppend" "archive" "attribute"
1577 "bre~ak" "bti~tle" "c~hange" "cl~ear" "col~umn" "conn~ect"
1578 "copy" "def~ine" "del" "desc~ribe" "disc~onnect" "ed~it"
1579 "exec~ute" "exit" "get" "help" "ho~st" "[$]" "i~nput" "l~ist"
1580 "passw~ord" "pau~se" "pri~nt" "pro~mpt" "quit" "recover"
1581 "repf~ooter" "reph~eader" "r~un" "sav~e" "sho~w" "shutdown"
1582 "spo~ol" "sta~rt" "startup" "store" "tim~ing" "tti~tle"
1583 "undef~ine" "var~iable" "whenever")
1586 (sql-regexp-abbrev "comp~ute")
1588 (sql-regexp-abbrev-list
1589 "avg" "cou~nt" "min~imum" "max~imum" "num~ber" "sum"
1593 (concat "\\(?:set\\s-+"
1594 (sql-regexp-abbrev-list
1595 "appi~nfo" "array~size" "auto~commit" "autop~rint"
1596 "autorecovery" "autot~race" "blo~ckterminator"
1597 "cmds~ep" "colsep" "com~patibility" "con~cat"
1598 "copyc~ommit" "copytypecheck" "def~ine" "describe"
1599 "echo" "editf~ile" "emb~edded" "esc~ape" "feed~back"
1600 "flagger" "flu~sh" "hea~ding" "heads~ep" "instance"
1601 "lin~esize" "lobof~fset" "long" "longc~hunksize"
1602 "mark~up" "newp~age" "null" "numf~ormat" "num~width"
1603 "pages~ize" "pau~se" "recsep" "recsepchar"
1604 "scan" "serverout~put" "shift~inout" "show~mode"
1605 "sqlbl~anklines" "sqlc~ase" "sqlco~ntinue"
1606 "sqln~umber" "sqlpluscompat~ibility" "sqlpre~fix"
1607 "sqlp~rompt" "sqlt~erminator" "suf~fix" "tab"
1608 "term~out" "ti~me" "timi~ng" "trim~out" "trims~pool"
1609 "und~erline" "ver~ify" "wra~p")
1612 "\\)\\(?:\\s-.*\\)?\\(?:[-]\n.*\\)*$")
1613 0 'font-lock-doc-face t
)
1616 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1617 "abs" "acos" "add_months" "appendchildxml" "ascii" "asciistr" "asin"
1618 "atan" "atan2" "avg" "bfilename" "bin_to_num" "bitand" "cardinality"
1619 "cast" "ceil" "chartorowid" "chr" "cluster_id" "cluster_probability"
1620 "cluster_set" "coalesce" "collect" "compose" "concat" "convert" "corr"
1621 "connect_by_root" "connect_by_iscycle" "connect_by_isleaf"
1622 "corr_k" "corr_s" "cos" "cosh" "count" "covar_pop" "covar_samp"
1623 "cube_table" "cume_dist" "current_date" "current_timestamp" "cv"
1624 "dataobj_to_partition" "dbtimezone" "decode" "decompose" "deletexml"
1625 "dense_rank" "depth" "deref" "dump" "empty_blob" "empty_clob"
1626 "existsnode" "exp" "extract" "extractvalue" "feature_id" "feature_set"
1627 "feature_value" "first" "first_value" "floor" "from_tz" "greatest"
1628 "grouping" "grouping_id" "group_id" "hextoraw" "initcap"
1629 "insertchildxml" "insertchildxmlafter" "insertchildxmlbefore"
1630 "insertxmlafter" "insertxmlbefore" "instr" "instr2" "instr4" "instrb"
1631 "instrc" "iteration_number" "lag" "last" "last_day" "last_value"
1632 "lead" "least" "length" "length2" "length4" "lengthb" "lengthc"
1633 "listagg" "ln" "lnnvl" "localtimestamp" "log" "lower" "lpad" "ltrim"
1634 "make_ref" "max" "median" "min" "mod" "months_between" "nanvl" "nchr"
1635 "new_time" "next_day" "nlssort" "nls_charset_decl_len"
1636 "nls_charset_id" "nls_charset_name" "nls_initcap" "nls_lower"
1637 "nls_upper" "nth_value" "ntile" "nullif" "numtodsinterval"
1638 "numtoyminterval" "nvl" "nvl2" "ora_dst_affected" "ora_dst_convert"
1639 "ora_dst_error" "ora_hash" "path" "percentile_cont" "percentile_disc"
1640 "percent_rank" "power" "powermultiset" "powermultiset_by_cardinality"
1641 "prediction" "prediction_bounds" "prediction_cost"
1642 "prediction_details" "prediction_probability" "prediction_set"
1643 "presentnnv" "presentv" "previous" "rank" "ratio_to_report" "rawtohex"
1644 "rawtonhex" "ref" "reftohex" "regexp_count" "regexp_instr"
1645 "regexp_replace" "regexp_substr" "regr_avgx" "regr_avgy" "regr_count"
1646 "regr_intercept" "regr_r2" "regr_slope" "regr_sxx" "regr_sxy"
1647 "regr_syy" "remainder" "replace" "round" "rowidtochar" "rowidtonchar"
1648 "row_number" "rpad" "rtrim" "scn_to_timestamp" "sessiontimezone" "set"
1649 "sign" "sin" "sinh" "soundex" "sqrt" "stats_binomial_test"
1650 "stats_crosstab" "stats_f_test" "stats_ks_test" "stats_mode"
1651 "stats_mw_test" "stats_one_way_anova" "stats_t_test_indep"
1652 "stats_t_test_indepu" "stats_t_test_one" "stats_t_test_paired"
1653 "stats_wsr_test" "stddev" "stddev_pop" "stddev_samp" "substr"
1654 "substr2" "substr4" "substrb" "substrc" "sum" "sysdate" "systimestamp"
1655 "sys_connect_by_path" "sys_context" "sys_dburigen" "sys_extract_utc"
1656 "sys_guid" "sys_typeid" "sys_xmlagg" "sys_xmlgen" "tan" "tanh"
1657 "timestamp_to_scn" "to_binary_double" "to_binary_float" "to_blob"
1658 "to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte"
1659 "to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp"
1660 "to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc"
1661 "tz_offset" "uid" "unistr" "updatexml" "upper" "user" "userenv"
1662 "value" "variance" "var_pop" "var_samp" "vsize" "width_bucket"
1663 "xmlagg" "xmlcast" "xmlcdata" "xmlcolattval" "xmlcomment" "xmlconcat"
1664 "xmldiff" "xmlelement" "xmlexists" "xmlforest" "xmlisvalid" "xmlparse"
1665 "xmlpatch" "xmlpi" "xmlquery" "xmlroot" "xmlsequence" "xmlserialize"
1666 "xmltable" "xmltransform"
1669 ;; See the table V$RESERVED_WORDS
1671 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1672 "abort" "access" "accessed" "account" "activate" "add" "admin"
1673 "advise" "after" "agent" "aggregate" "all" "allocate" "allow" "alter"
1674 "always" "analyze" "ancillary" "and" "any" "apply" "archive"
1675 "archivelog" "array" "as" "asc" "associate" "at" "attribute"
1676 "attributes" "audit" "authenticated" "authid" "authorization" "auto"
1677 "autoallocate" "automatic" "availability" "backup" "before" "begin"
1678 "behalf" "between" "binding" "bitmap" "block" "blocksize" "body"
1679 "both" "buffer_pool" "build" "by" "cache" "call" "cancel"
1680 "cascade" "case" "category" "certificate" "chained" "change" "check"
1681 "checkpoint" "child" "chunk" "class" "clear" "clone" "close" "cluster"
1682 "column" "column_value" "columns" "comment" "commit" "committed"
1683 "compatibility" "compile" "complete" "composite_limit" "compress"
1684 "compute" "connect" "connect_time" "consider" "consistent"
1685 "constraint" "constraints" "constructor" "contents" "context"
1686 "continue" "controlfile" "corruption" "cost" "cpu_per_call"
1687 "cpu_per_session" "create" "cross" "cube" "current" "currval" "cycle"
1688 "dangling" "data" "database" "datafile" "datafiles" "day" "ddl"
1689 "deallocate" "debug" "default" "deferrable" "deferred" "definer"
1690 "delay" "delete" "demand" "desc" "determines" "deterministic"
1691 "dictionary" "dimension" "directory" "disable" "disassociate"
1692 "disconnect" "distinct" "distinguished" "distributed" "dml" "drop"
1693 "each" "element" "else" "enable" "end" "equals_path" "escape"
1694 "estimate" "except" "exceptions" "exchange" "excluding" "exists"
1695 "expire" "explain" "extent" "external" "externally"
1696 "failed_login_attempts" "fast" "file" "final" "finish" "flush" "for"
1697 "force" "foreign" "freelist" "freelists" "freepools" "fresh" "from"
1698 "full" "function" "functions" "generated" "global" "global_name"
1699 "globally" "grant" "group" "grouping" "groups" "guard" "hash"
1700 "hashkeys" "having" "heap" "hierarchy" "id" "identified" "identifier"
1701 "idle_time" "immediate" "in" "including" "increment" "index" "indexed"
1702 "indexes" "indextype" "indextypes" "indicator" "initial" "initialized"
1703 "initially" "initrans" "inner" "insert" "instance" "instantiable"
1704 "instead" "intersect" "into" "invalidate" "is" "isolation" "java"
1705 "join" "keep" "key" "kill" "language" "left" "less" "level"
1706 "levels" "library" "like" "like2" "like4" "likec" "limit" "link"
1707 "list" "lob" "local" "location" "locator" "lock" "log" "logfile"
1708 "logging" "logical" "logical_reads_per_call"
1709 "logical_reads_per_session" "managed" "management" "manual" "map"
1710 "mapping" "master" "matched" "materialized" "maxdatafiles"
1711 "maxextents" "maximize" "maxinstances" "maxlogfiles" "maxloghistory"
1712 "maxlogmembers" "maxsize" "maxtrans" "maxvalue" "member" "memory"
1713 "merge" "migrate" "minextents" "minimize" "minimum" "minus" "minvalue"
1714 "mode" "modify" "monitoring" "month" "mount" "move" "movement" "name"
1715 "named" "natural" "nested" "never" "new" "next" "nextval" "no"
1716 "noarchivelog" "noaudit" "nocache" "nocompress" "nocopy" "nocycle"
1717 "nodelay" "noforce" "nologging" "nomapping" "nomaxvalue" "nominimize"
1718 "nominvalue" "nomonitoring" "none" "noorder" "noparallel" "norely"
1719 "noresetlogs" "noreverse" "normal" "norowdependencies" "nosort"
1720 "noswitch" "not" "nothing" "notimeout" "novalidate" "nowait" "null"
1721 "nulls" "object" "of" "off" "offline" "oidindex" "old" "on" "online"
1722 "only" "open" "operator" "optimal" "option" "or" "order"
1723 "organization" "out" "outer" "outline" "overflow" "overriding"
1724 "package" "packages" "parallel" "parallel_enable" "parameters"
1725 "parent" "partition" "partitions" "password" "password_grace_time"
1726 "password_life_time" "password_lock_time" "password_reuse_max"
1727 "password_reuse_time" "password_verify_function" "pctfree"
1728 "pctincrease" "pctthreshold" "pctused" "pctversion" "percent"
1729 "performance" "permanent" "pfile" "physical" "pipelined" "plan"
1730 "post_transaction" "pragma" "prebuilt" "preserve" "primary" "private"
1731 "private_sga" "privileges" "procedure" "profile" "protection" "public"
1732 "purge" "query" "quiesce" "quota" "range" "read" "reads" "rebuild"
1733 "records_per_block" "recover" "recovery" "recycle" "reduced" "ref"
1734 "references" "referencing" "refresh" "register" "reject" "relational"
1735 "rely" "rename" "reset" "resetlogs" "resize" "resolve" "resolver"
1736 "resource" "restrict" "restrict_references" "restricted" "result"
1737 "resumable" "resume" "retention" "return" "returning" "reuse"
1738 "reverse" "revoke" "rewrite" "right" "rnds" "rnps" "role" "roles"
1739 "rollback" "rollup" "row" "rowdependencies" "rownum" "rows" "sample"
1740 "savepoint" "scan" "schema" "scn" "scope" "segment" "select"
1741 "selectivity" "self" "sequence" "serializable" "session"
1742 "sessions_per_user" "set" "sets" "settings" "shared" "shared_pool"
1743 "shrink" "shutdown" "siblings" "sid" "single" "size" "skip" "some"
1744 "sort" "source" "space" "specification" "spfile" "split" "standby"
1745 "start" "statement_id" "static" "statistics" "stop" "storage" "store"
1746 "structure" "subpartition" "subpartitions" "substitutable"
1747 "successful" "supplemental" "suspend" "switch" "switchover" "synonym"
1748 "sys" "system" "table" "tables" "tablespace" "tempfile" "template"
1749 "temporary" "test" "than" "then" "thread" "through" "time_zone"
1750 "timeout" "to" "trace" "transaction" "trigger" "triggers" "truncate"
1751 "trust" "type" "types" "unarchived" "under" "under_path" "undo"
1752 "uniform" "union" "unique" "unlimited" "unlock" "unquiesce"
1753 "unrecoverable" "until" "unusable" "unused" "update" "upgrade" "usage"
1754 "use" "using" "validate" "validation" "value" "values" "variable"
1755 "varray" "version" "view" "wait" "when" "whenever" "where" "with"
1756 "without" "wnds" "wnps" "work" "write" "xmldata" "xmlschema" "xmltype"
1759 ;; Oracle Data Types
1760 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1761 "bfile" "binary_double" "binary_float" "blob" "byte" "char" "charbyte"
1762 "clob" "date" "day" "float" "interval" "local" "long" "longraw"
1763 "minute" "month" "nchar" "nclob" "number" "nvarchar2" "raw" "rowid" "second"
1764 "time" "timestamp" "urowid" "varchar2" "with" "year" "zone"
1767 ;; Oracle PL/SQL Attributes
1768 (sql-font-lock-keywords-builder 'font-lock-builtin-face
'("%" .
"\\b")
1769 "bulk_exceptions" "bulk_rowcount" "found" "isopen" "notfound"
1770 "rowcount" "rowtype" "type"
1773 ;; Oracle PL/SQL Functions
1774 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1775 "delete" "trim" "extend" "exists" "first" "last" "count" "limit"
1779 ;; Oracle PL/SQL Reserved words
1780 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1781 "all" "alter" "and" "any" "as" "asc" "at" "begin" "between" "by"
1782 "case" "check" "clusters" "cluster" "colauth" "columns" "compress"
1783 "connect" "crash" "create" "cursor" "declare" "default" "desc"
1784 "distinct" "drop" "else" "end" "exception" "exclusive" "fetch" "for"
1785 "from" "function" "goto" "grant" "group" "having" "identified" "if"
1786 "in" "index" "indexes" "insert" "intersect" "into" "is" "like" "lock"
1787 "minus" "mode" "nocompress" "not" "nowait" "null" "of" "on" "option"
1788 "or" "order" "overlaps" "procedure" "public" "resource" "revoke"
1789 "select" "share" "size" "sql" "start" "subtype" "tabauth" "table"
1790 "then" "to" "type" "union" "unique" "update" "values" "view" "views"
1791 "when" "where" "with"
1794 "raise_application_error"
1797 ;; Oracle PL/SQL Keywords
1798 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
1799 "a" "add" "agent" "aggregate" "array" "attribute" "authid" "avg"
1800 "bfile_base" "binary" "blob_base" "block" "body" "both" "bound" "bulk"
1801 "byte" "c" "call" "calling" "cascade" "char" "char_base" "character"
1802 "charset" "charsetform" "charsetid" "clob_base" "close" "collect"
1803 "comment" "commit" "committed" "compiled" "constant" "constructor"
1804 "context" "continue" "convert" "count" "current" "customdatum"
1805 "dangling" "data" "date" "date_base" "day" "define" "delete"
1806 "deterministic" "double" "duration" "element" "elsif" "empty" "escape"
1807 "except" "exceptions" "execute" "exists" "exit" "external" "final"
1808 "fixed" "float" "forall" "force" "general" "hash" "heap" "hidden"
1809 "hour" "immediate" "including" "indicator" "indices" "infinite"
1810 "instantiable" "int" "interface" "interval" "invalidate" "isolation"
1811 "java" "language" "large" "leading" "length" "level" "library" "like2"
1812 "like4" "likec" "limit" "limited" "local" "long" "loop" "map" "max"
1813 "maxlen" "member" "merge" "min" "minute" "mod" "modify" "month"
1814 "multiset" "name" "nan" "national" "native" "nchar" "new" "nocopy"
1815 "number_base" "object" "ocicoll" "ocidate" "ocidatetime" "ociduration"
1816 "ociinterval" "ociloblocator" "ocinumber" "ociraw" "ociref"
1817 "ocirefcursor" "ocirowid" "ocistring" "ocitype" "old" "only" "opaque"
1818 "open" "operator" "oracle" "oradata" "organization" "orlany" "orlvary"
1819 "others" "out" "overriding" "package" "parallel_enable" "parameter"
1820 "parameters" "parent" "partition" "pascal" "pipe" "pipelined" "pragma"
1821 "precision" "prior" "private" "raise" "range" "raw" "read" "record"
1822 "ref" "reference" "relies_on" "rem" "remainder" "rename" "result"
1823 "result_cache" "return" "returning" "reverse" "rollback" "row"
1824 "sample" "save" "savepoint" "sb1" "sb2" "sb4" "second" "segment"
1825 "self" "separate" "sequence" "serializable" "set" "short" "size_t"
1826 "some" "sparse" "sqlcode" "sqldata" "sqlname" "sqlstate" "standard"
1827 "static" "stddev" "stored" "string" "struct" "style" "submultiset"
1828 "subpartition" "substitutable" "sum" "synonym" "tdo" "the" "time"
1829 "timestamp" "timezone_abbr" "timezone_hour" "timezone_minute"
1830 "timezone_region" "trailing" "transaction" "transactional" "trusted"
1831 "ub1" "ub2" "ub4" "under" "unsigned" "untrusted" "use" "using"
1832 "valist" "value" "variable" "variance" "varray" "varying" "void"
1833 "while" "work" "wrapped" "write" "year" "zone"
1835 "autonomous_transaction" "exception_init" "inline"
1836 "restrict_references" "serially_reusable"
1839 ;; Oracle PL/SQL Data Types
1840 (sql-font-lock-keywords-builder 'font-lock-type-face nil
1841 "\"BINARY LARGE OBJECT\"" "\"CHAR LARGE OBJECT\"" "\"CHAR VARYING\""
1842 "\"CHARACTER LARGE OBJECT\"" "\"CHARACTER VARYING\""
1843 "\"DOUBLE PRECISION\"" "\"INTERVAL DAY TO SECOND\""
1844 "\"INTERVAL YEAR TO MONTH\"" "\"LONG RAW\"" "\"NATIONAL CHAR\""
1845 "\"NATIONAL CHARACTER LARGE OBJECT\"" "\"NATIONAL CHARACTER\""
1846 "\"NCHAR LARGE OBJECT\"" "\"NCHAR\"" "\"NCLOB\"" "\"NVARCHAR2\""
1847 "\"TIME WITH TIME ZONE\"" "\"TIMESTAMP WITH LOCAL TIME ZONE\""
1848 "\"TIMESTAMP WITH TIME ZONE\""
1849 "bfile" "bfile_base" "binary_double" "binary_float" "binary_integer"
1850 "blob" "blob_base" "boolean" "char" "character" "char_base" "clob"
1851 "clob_base" "cursor" "date" "day" "dec" "decimal"
1852 "dsinterval_unconstrained" "float" "int" "integer" "interval" "local"
1853 "long" "mlslabel" "month" "natural" "naturaln" "nchar_cs" "number"
1854 "number_base" "numeric" "pls_integer" "positive" "positiven" "raw"
1855 "real" "ref" "rowid" "second" "signtype" "simple_double"
1856 "simple_float" "simple_integer" "smallint" "string" "time" "timestamp"
1857 "timestamp_ltz_unconstrained" "timestamp_tz_unconstrained"
1858 "timestamp_unconstrained" "time_tz_unconstrained" "time_unconstrained"
1859 "to" "urowid" "varchar" "varchar2" "with" "year"
1860 "yminterval_unconstrained" "zone"
1863 ;; Oracle PL/SQL Exceptions
1864 (sql-font-lock-keywords-builder 'font-lock-warning-face nil
1865 "access_into_null" "case_not_found" "collection_is_null"
1866 "cursor_already_open" "dup_val_on_index" "invalid_cursor"
1867 "invalid_number" "login_denied" "no_data_found" "no_data_needed"
1868 "not_logged_on" "program_error" "rowtype_mismatch" "self_is_null"
1869 "storage_error" "subscript_beyond_count" "subscript_outside_limit"
1870 "sys_invalid_rowid" "timeout_on_resource" "too_many_rows"
1871 "value_error" "zero_divide"
1874 "Oracle SQL keywords used by font-lock.
1876 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1877 regular expressions are created during compilation by calling the
1878 function `regexp-opt'. Therefore, take a look at the source before
1879 you define your own `sql-mode-oracle-font-lock-keywords'. You may want
1880 to add functions and PL/SQL keywords.")
1882 (defvar sql-mode-postgres-font-lock-keywords
1885 ;; Postgres psql commands
1886 '("^\\s-*\\\\.*$" . font-lock-doc-face
)
1888 ;; Postgres unreserved words but may have meaning
1889 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
"a"
1890 "abs" "absent" "according" "ada" "alias" "allocate" "are" "array_agg"
1891 "asensitive" "atomic" "attribute" "attributes" "avg" "base64"
1892 "bernoulli" "bit_length" "bitvar" "blob" "blocked" "bom" "breadth" "c"
1893 "call" "cardinality" "catalog_name" "ceil" "ceiling" "char_length"
1894 "character_length" "character_set_catalog" "character_set_name"
1895 "character_set_schema" "characters" "checked" "class_origin" "clob"
1896 "cobol" "collation" "collation_catalog" "collation_name"
1897 "collation_schema" "collect" "column_name" "columns"
1898 "command_function" "command_function_code" "completion" "condition"
1899 "condition_number" "connect" "connection_name" "constraint_catalog"
1900 "constraint_name" "constraint_schema" "constructor" "contains"
1901 "control" "convert" "corr" "corresponding" "count" "covar_pop"
1902 "covar_samp" "cube" "cume_dist" "current_default_transform_group"
1903 "current_path" "current_transform_group_for_type" "cursor_name"
1904 "datalink" "datetime_interval_code" "datetime_interval_precision" "db"
1905 "defined" "degree" "dense_rank" "depth" "deref" "derived" "describe"
1906 "descriptor" "destroy" "destructor" "deterministic" "diagnostics"
1907 "disconnect" "dispatch" "dlnewcopy" "dlpreviouscopy" "dlurlcomplete"
1908 "dlurlcompleteonly" "dlurlcompletewrite" "dlurlpath" "dlurlpathonly"
1909 "dlurlpathwrite" "dlurlscheme" "dlurlserver" "dlvalue" "dynamic"
1910 "dynamic_function" "dynamic_function_code" "element" "empty"
1911 "end-exec" "equals" "every" "exception" "exec" "existing" "exp" "file"
1912 "filter" "final" "first_value" "flag" "floor" "fortran" "found" "free"
1913 "fs" "fusion" "g" "general" "generated" "get" "go" "goto" "grouping"
1914 "hex" "hierarchy" "host" "id" "ignore" "implementation" "import"
1915 "indent" "indicator" "infix" "initialize" "instance" "instantiable"
1916 "integrity" "intersection" "iterate" "k" "key_member" "key_type" "lag"
1917 "last_value" "lateral" "lead" "length" "less" "library" "like_regex"
1918 "link" "ln" "locator" "lower" "m" "map" "matched" "max"
1919 "max_cardinality" "member" "merge" "message_length"
1920 "message_octet_length" "message_text" "method" "min" "mod" "modifies"
1921 "modify" "module" "more" "multiset" "mumps" "namespace" "nclob"
1922 "nesting" "new" "nfc" "nfd" "nfkc" "nfkd" "nil" "normalize"
1923 "normalized" "nth_value" "ntile" "nullable" "number"
1924 "occurrences_regex" "octet_length" "octets" "old" "open" "operation"
1925 "ordering" "ordinality" "others" "output" "overriding" "p" "pad"
1926 "parameter" "parameter_mode" "parameter_name"
1927 "parameter_ordinal_position" "parameter_specific_catalog"
1928 "parameter_specific_name" "parameter_specific_schema" "parameters"
1929 "pascal" "passing" "passthrough" "percent_rank" "percentile_cont"
1930 "percentile_disc" "permission" "pli" "position_regex" "postfix"
1931 "power" "prefix" "preorder" "public" "rank" "reads" "recovery" "ref"
1932 "referencing" "regr_avgx" "regr_avgy" "regr_count" "regr_intercept"
1933 "regr_r2" "regr_slope" "regr_sxx" "regr_sxy" "regr_syy" "requiring"
1934 "respect" "restore" "result" "return" "returned_cardinality"
1935 "returned_length" "returned_octet_length" "returned_sqlstate" "rollup"
1936 "routine" "routine_catalog" "routine_name" "routine_schema"
1937 "row_count" "row_number" "scale" "schema_name" "scope" "scope_catalog"
1938 "scope_name" "scope_schema" "section" "selective" "self" "sensitive"
1939 "server_name" "sets" "size" "source" "space" "specific"
1940 "specific_name" "specifictype" "sql" "sqlcode" "sqlerror"
1941 "sqlexception" "sqlstate" "sqlwarning" "sqrt" "state" "static"
1942 "stddev_pop" "stddev_samp" "structure" "style" "subclass_origin"
1943 "sublist" "submultiset" "substring_regex" "sum" "system_user" "t"
1944 "table_name" "tablesample" "terminate" "than" "ties" "timezone_hour"
1945 "timezone_minute" "token" "top_level_count" "transaction_active"
1946 "transactions_committed" "transactions_rolled_back" "transform"
1947 "transforms" "translate" "translate_regex" "translation"
1948 "trigger_catalog" "trigger_name" "trigger_schema" "trim_array"
1949 "uescape" "under" "unlink" "unnamed" "unnest" "untyped" "upper" "uri"
1950 "usage" "user_defined_type_catalog" "user_defined_type_code"
1951 "user_defined_type_name" "user_defined_type_schema" "var_pop"
1952 "var_samp" "varbinary" "variable" "whenever" "width_bucket" "within"
1953 "xmlagg" "xmlbinary" "xmlcast" "xmlcomment" "xmldeclaration"
1954 "xmldocument" "xmlexists" "xmliterate" "xmlnamespaces" "xmlquery"
1955 "xmlschema" "xmltable" "xmltext" "xmlvalidate"
1958 ;; Postgres non-reserved words
1959 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
1960 "abort" "absolute" "access" "action" "add" "admin" "after" "aggregate"
1961 "also" "alter" "always" "assertion" "assignment" "at" "backward"
1962 "before" "begin" "between" "by" "cache" "called" "cascade" "cascaded"
1963 "catalog" "chain" "characteristics" "checkpoint" "class" "close"
1964 "cluster" "coalesce" "comment" "comments" "commit" "committed"
1965 "configuration" "connection" "constraints" "content" "continue"
1966 "conversion" "copy" "cost" "createdb" "createrole" "createuser" "csv"
1967 "current" "cursor" "cycle" "data" "database" "day" "deallocate" "dec"
1968 "declare" "defaults" "deferred" "definer" "delete" "delimiter"
1969 "delimiters" "dictionary" "disable" "discard" "document" "domain"
1970 "drop" "each" "enable" "encoding" "encrypted" "enum" "escape"
1971 "exclude" "excluding" "exclusive" "execute" "exists" "explain"
1972 "external" "extract" "family" "first" "float" "following" "force"
1973 "forward" "function" "functions" "global" "granted" "greatest"
1974 "handler" "header" "hold" "hour" "identity" "if" "immediate"
1975 "immutable" "implicit" "including" "increment" "index" "indexes"
1976 "inherit" "inherits" "inline" "inout" "input" "insensitive" "insert"
1977 "instead" "invoker" "isolation" "key" "language" "large" "last"
1978 "lc_collate" "lc_ctype" "least" "level" "listen" "load" "local"
1979 "location" "lock" "login" "mapping" "match" "maxvalue" "minute"
1980 "minvalue" "mode" "month" "move" "name" "names" "national" "nchar"
1981 "next" "no" "nocreatedb" "nocreaterole" "nocreateuser" "noinherit"
1982 "nologin" "none" "nosuperuser" "nothing" "notify" "nowait" "nullif"
1983 "nulls" "object" "of" "oids" "operator" "option" "options" "out"
1984 "overlay" "owned" "owner" "parser" "partial" "partition" "password"
1985 "plans" "position" "preceding" "prepare" "prepared" "preserve" "prior"
1986 "privileges" "procedural" "procedure" "quote" "range" "read"
1987 "reassign" "recheck" "recursive" "reindex" "relative" "release"
1988 "rename" "repeatable" "replace" "replica" "reset" "restart" "restrict"
1989 "returns" "revoke" "role" "rollback" "row" "rows" "rule" "savepoint"
1990 "schema" "scroll" "search" "second" "security" "sequence" "sequences"
1991 "serializable" "server" "session" "set" "setof" "share" "show"
1992 "simple" "stable" "standalone" "start" "statement" "statistics"
1993 "stdin" "stdout" "storage" "strict" "strip" "substring" "superuser"
1994 "sysid" "system" "tables" "tablespace" "temp" "template" "temporary"
1995 "transaction" "treat" "trigger" "trim" "truncate" "trusted" "type"
1996 "unbounded" "uncommitted" "unencrypted" "unknown" "unlisten" "until"
1997 "update" "vacuum" "valid" "validator" "value" "values" "version"
1998 "view" "volatile" "whitespace" "work" "wrapper" "write"
1999 "xmlattributes" "xmlconcat" "xmlelement" "xmlforest" "xmlparse"
2000 "xmlpi" "xmlroot" "xmlserialize" "year" "yes"
2003 ;; Postgres Reserved
2004 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2005 "all" "analyse" "analyze" "and" "any" "array" "asc" "as" "asymmetric"
2006 "authorization" "binary" "both" "case" "cast" "check" "collate"
2007 "column" "concurrently" "constraint" "create" "cross"
2008 "current_catalog" "current_date" "current_role" "current_schema"
2009 "current_time" "current_timestamp" "current_user" "default"
2010 "deferrable" "desc" "distinct" "do" "else" "end" "except" "false"
2011 "fetch" "foreign" "for" "freeze" "from" "full" "grant" "group"
2012 "having" "ilike" "initially" "inner" "in" "intersect" "into" "isnull"
2013 "is" "join" "leading" "left" "like" "limit" "localtime"
2014 "localtimestamp" "natural" "notnull" "not" "null" "off" "offset"
2015 "only" "on" "order" "or" "outer" "overlaps" "over" "placing" "primary"
2016 "references" "returning" "right" "select" "session_user" "similar"
2017 "some" "symmetric" "table" "then" "to" "trailing" "true" "union"
2018 "unique" "user" "using" "variadic" "verbose" "when" "where" "window"
2022 ;; Postgres Data Types
2023 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2024 "bigint" "bigserial" "bit" "bool" "boolean" "box" "bytea" "char"
2025 "character" "cidr" "circle" "date" "decimal" "double" "float4"
2026 "float8" "inet" "int" "int2" "int4" "int8" "integer" "interval" "line"
2027 "lseg" "macaddr" "money" "numeric" "path" "point" "polygon"
2028 "precision" "real" "serial" "serial4" "serial8" "smallint" "text"
2029 "time" "timestamp" "timestamptz" "timetz" "tsquery" "tsvector"
2030 "txid_snapshot" "uuid" "varbit" "varchar" "varying" "without"
2034 "Postgres SQL keywords used by font-lock.
2036 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2037 regular expressions are created during compilation by calling the
2038 function `regexp-opt'. Therefore, take a look at the source before
2039 you define your own `sql-mode-postgres-font-lock-keywords'.")
2041 (defvar sql-mode-linter-font-lock-keywords
2045 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2046 "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel"
2047 "committed" "count" "countblob" "cross" "current" "data" "database"
2048 "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred"
2049 "denied" "description" "device" "difference" "directory" "error"
2050 "escape" "euc" "exclusive" "external" "extfile" "false" "file"
2051 "filename" "filesize" "filetime" "filter" "findblob" "first" "foreign"
2052 "full" "fuzzy" "global" "granted" "ignore" "immediate" "increment"
2053 "indexes" "indexfile" "indexfiles" "indextime" "initial" "integrity"
2054 "internal" "key" "last_autoinc" "last_rowid" "limit" "linter"
2055 "linter_file_device" "linter_file_size" "linter_name_length" "ln"
2056 "local" "login" "maxisn" "maxrow" "maxrowid" "maxvalue" "message"
2057 "minvalue" "module" "names" "national" "natural" "new" "new_table"
2058 "no" "node" "noneuc" "nulliferror" "numbers" "off" "old" "old_table"
2059 "only" "operation" "optimistic" "option" "page" "partially" "password"
2060 "phrase" "plan" "precision" "primary" "priority" "privileges"
2061 "proc_info_size" "proc_par_name_len" "protocol" "quant" "range" "raw"
2062 "read" "record" "records" "references" "remote" "rename" "replication"
2063 "restart" "rewrite" "root" "row" "rule" "savepoint" "security"
2064 "sensitive" "sequence" "serializable" "server" "since" "size" "some"
2065 "startup" "statement" "station" "success" "sys_guid" "tables" "test"
2066 "timeout" "trace" "transaction" "translation" "trigger"
2067 "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown"
2068 "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes"
2069 "wait" "windows_code" "workspace" "write" "xml"
2073 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2074 "access" "action" "add" "address" "after" "all" "alter" "always" "and"
2075 "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit"
2076 "aud_obj_name_len" "backup" "base" "before" "between" "blobfile"
2077 "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check"
2078 "clear" "close" "column" "comment" "commit" "connect" "contains"
2079 "correct" "create" "delete" "desc" "disable" "disconnect" "distinct"
2080 "drop" "each" "ef" "else" "enable" "end" "event" "except" "exclude"
2081 "execute" "exists" "extract" "fetch" "finish" "for" "from" "get"
2082 "grant" "group" "having" "identified" "in" "index" "inner" "insert"
2083 "instead" "intersect" "into" "is" "isolation" "join" "left" "level"
2084 "like" "lock" "mode" "modify" "not" "nowait" "null" "of" "on" "open"
2085 "or" "order" "outer" "owner" "press" "prior" "procedure" "public"
2086 "purge" "rebuild" "resource" "restrict" "revoke" "right" "role"
2087 "rollback" "rownum" "select" "session" "set" "share" "shutdown"
2088 "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then"
2089 "to" "union" "unique" "unlock" "until" "update" "using" "values"
2090 "view" "when" "where" "with" "without"
2094 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
2095 "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime"
2096 "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw"
2097 "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log"
2098 "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl"
2099 "octet_length" "power" "rand" "rawtohex" "repeat_string"
2100 "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex"
2101 "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date"
2102 "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode"
2103 "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap"
2104 "instr" "least" "multime" "replace" "width"
2107 ;; Linter Data Types
2108 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2109 "bigint" "bitmap" "blob" "boolean" "char" "character" "date"
2110 "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar"
2111 "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte"
2115 "Linter SQL keywords used by font-lock.
2117 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2118 regular expressions are created during compilation by calling the
2119 function `regexp-opt'.")
2121 (defvar sql-mode-ms-font-lock-keywords
2124 ;; MS isql/osql Commands
2127 "^\\(?:\\(?:set\\s-+\\(?:"
2129 "datefirst" "dateformat" "deadlock_priority" "lock_timeout"
2130 "concat_null_yields_null" "cursor_close_on_commit"
2131 "disable_def_cnst_chk" "fips_flagger" "identity_insert" "language"
2132 "offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly"
2133 "nocount" "noexec" "numeric_roundabort" "parseonly"
2134 "query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults"
2135 "ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding"
2136 "ansi_warnings" "forceplan" "showplan_all" "showplan_text"
2137 "statistics" "implicit_transactions" "remote_proc_transactions"
2138 "transaction" "xact_abort"
2140 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$")
2141 'font-lock-doc-face
)
2144 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2145 "absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization"
2146 "avg" "backup" "begin" "between" "break" "browse" "bulk" "by"
2147 "cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce"
2148 "column" "commit" "committed" "compute" "confirm" "constraint"
2149 "contains" "containstable" "continue" "controlrow" "convert" "count"
2150 "create" "cross" "current" "current_date" "current_time"
2151 "current_timestamp" "current_user" "database" "deallocate" "declare"
2152 "default" "delete" "deny" "desc" "disk" "distinct" "distributed"
2153 "double" "drop" "dummy" "dump" "else" "end" "errlvl" "errorexit"
2154 "escape" "except" "exec" "execute" "exists" "exit" "fetch" "file"
2155 "fillfactor" "first" "floppy" "for" "foreign" "freetext"
2156 "freetexttable" "from" "full" "goto" "grant" "group" "having"
2157 "holdlock" "identity" "identity_insert" "identitycol" "if" "in"
2158 "index" "inner" "insert" "intersect" "into" "is" "isolation" "join"
2159 "key" "kill" "last" "left" "level" "like" "lineno" "load" "max" "min"
2160 "mirrorexit" "national" "next" "nocheck" "nolock" "nonclustered" "not"
2161 "null" "nullif" "of" "off" "offsets" "on" "once" "only" "open"
2162 "opendatasource" "openquery" "openrowset" "option" "or" "order"
2163 "outer" "output" "over" "paglock" "percent" "perm" "permanent" "pipe"
2164 "plan" "precision" "prepare" "primary" "print" "prior" "privileges"
2165 "proc" "procedure" "processexit" "public" "raiserror" "read"
2166 "readcommitted" "readpast" "readtext" "readuncommitted" "reconfigure"
2167 "references" "relative" "repeatable" "repeatableread" "replication"
2168 "restore" "restrict" "return" "revoke" "right" "rollback" "rowcount"
2169 "rowguidcol" "rowlock" "rule" "save" "schema" "select" "serializable"
2170 "session_user" "set" "shutdown" "some" "statistics" "sum"
2171 "system_user" "table" "tablock" "tablockx" "tape" "temp" "temporary"
2172 "textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate"
2173 "tsequal" "uncommitted" "union" "unique" "update" "updatetext"
2174 "updlock" "use" "user" "values" "view" "waitfor" "when" "where"
2175 "while" "with" "work" "writetext" "collate" "function" "openxml"
2180 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
2181 "@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts"
2182 "@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy"
2183 "@@langid" "@@language" "@@lock_timeout" "@@max_connections"
2184 "@@max_precision" "@@nestlevel" "@@options" "@@pack_received"
2185 "@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount"
2186 "@@servername" "@@servicename" "@@spid" "@@textsize" "@@timeticks"
2187 "@@total_errors" "@@total_read" "@@total_write" "@@trancount"
2188 "@@version" "abs" "acos" "and" "app_name" "ascii" "asin" "atan" "atn2"
2189 "avg" "case" "cast" "ceiling" "char" "charindex" "coalesce"
2190 "col_length" "col_name" "columnproperty" "containstable" "convert"
2191 "cos" "cot" "count" "current_timestamp" "current_user" "cursor_status"
2192 "databaseproperty" "datalength" "dateadd" "datediff" "datename"
2193 "datepart" "day" "db_id" "db_name" "degrees" "difference" "exp"
2194 "file_id" "file_name" "filegroup_id" "filegroup_name"
2195 "filegroupproperty" "fileproperty" "floor" "formatmessage"
2196 "freetexttable" "fulltextcatalogproperty" "fulltextserviceproperty"
2197 "getansinull" "getdate" "grouping" "host_id" "host_name" "ident_incr"
2198 "ident_seed" "identity" "index_col" "indexproperty" "is_member"
2199 "is_srvrolemember" "isdate" "isnull" "isnumeric" "left" "len" "log"
2200 "log10" "lower" "ltrim" "max" "min" "month" "nchar" "newid" "nullif"
2201 "object_id" "object_name" "objectproperty" "openquery" "openrowset"
2202 "parsename" "patindex" "patindex" "permissions" "pi" "power"
2203 "quotename" "radians" "rand" "replace" "replicate" "reverse" "right"
2204 "round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt"
2205 "square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum"
2206 "suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan"
2207 "textptr" "textvalid" "typeproperty" "unicode" "upper" "user"
2208 "user_id" "user_name" "var" "varp" "year"
2212 '("\\b@[a-zA-Z0-9_]*\\b" . font-lock-variable-name-face
)
2215 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2216 "binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal"
2217 "double" "float" "image" "int" "integer" "money" "national" "nchar"
2218 "ntext" "numeric" "numeric" "nvarchar" "precision" "real"
2219 "smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint"
2220 "uniqueidentifier" "varbinary" "varchar" "varying"
2223 "Microsoft SQLServer SQL keywords used by font-lock.
2225 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2226 regular expressions are created during compilation by calling the
2227 function `regexp-opt'. Therefore, take a look at the source before
2228 you define your own `sql-mode-ms-font-lock-keywords'.")
2230 (defvar sql-mode-sybase-font-lock-keywords nil
2231 "Sybase SQL keywords used by font-lock.
2233 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2234 regular expressions are created during compilation by calling the
2235 function `regexp-opt'. Therefore, take a look at the source before
2236 you define your own `sql-mode-sybase-font-lock-keywords'.")
2238 (defvar sql-mode-informix-font-lock-keywords nil
2239 "Informix SQL keywords used by font-lock.
2241 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2242 regular expressions are created during compilation by calling the
2243 function `regexp-opt'. Therefore, take a look at the source before
2244 you define your own `sql-mode-informix-font-lock-keywords'.")
2246 (defvar sql-mode-interbase-font-lock-keywords nil
2247 "Interbase SQL keywords used by font-lock.
2249 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2250 regular expressions are created during compilation by calling the
2251 function `regexp-opt'. Therefore, take a look at the source before
2252 you define your own `sql-mode-interbase-font-lock-keywords'.")
2254 (defvar sql-mode-ingres-font-lock-keywords nil
2255 "Ingres SQL keywords used by font-lock.
2257 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2258 regular expressions are created during compilation by calling the
2259 function `regexp-opt'. Therefore, take a look at the source before
2260 you define your own `sql-mode-interbase-font-lock-keywords'.")
2262 (defvar sql-mode-solid-font-lock-keywords nil
2263 "Solid SQL keywords used by font-lock.
2265 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2266 regular expressions are created during compilation by calling the
2267 function `regexp-opt'. Therefore, take a look at the source before
2268 you define your own `sql-mode-solid-font-lock-keywords'.")
2270 (defvar sql-mode-mysql-font-lock-keywords
2274 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
2275 "ascii" "avg" "bdmpolyfromtext" "bdmpolyfromwkb" "bdpolyfromtext"
2276 "bdpolyfromwkb" "benchmark" "bin" "bit_and" "bit_length" "bit_or"
2277 "bit_xor" "both" "cast" "char_length" "character_length" "coalesce"
2278 "concat" "concat_ws" "connection_id" "conv" "convert" "count"
2279 "curdate" "current_date" "current_time" "current_timestamp" "curtime"
2280 "elt" "encrypt" "export_set" "field" "find_in_set" "found_rows" "from"
2281 "geomcollfromtext" "geomcollfromwkb" "geometrycollectionfromtext"
2282 "geometrycollectionfromwkb" "geometryfromtext" "geometryfromwkb"
2283 "geomfromtext" "geomfromwkb" "get_lock" "group_concat" "hex" "ifnull"
2284 "instr" "interval" "isnull" "last_insert_id" "lcase" "leading"
2285 "length" "linefromtext" "linefromwkb" "linestringfromtext"
2286 "linestringfromwkb" "load_file" "locate" "lower" "lpad" "ltrim"
2287 "make_set" "master_pos_wait" "max" "mid" "min" "mlinefromtext"
2288 "mlinefromwkb" "mpointfromtext" "mpointfromwkb" "mpolyfromtext"
2289 "mpolyfromwkb" "multilinestringfromtext" "multilinestringfromwkb"
2290 "multipointfromtext" "multipointfromwkb" "multipolygonfromtext"
2291 "multipolygonfromwkb" "now" "nullif" "oct" "octet_length" "ord"
2292 "pointfromtext" "pointfromwkb" "polyfromtext" "polyfromwkb"
2293 "polygonfromtext" "polygonfromwkb" "position" "quote" "rand"
2294 "release_lock" "repeat" "replace" "reverse" "rpad" "rtrim" "soundex"
2295 "space" "std" "stddev" "substring" "substring_index" "sum" "sysdate"
2296 "trailing" "trim" "ucase" "unix_timestamp" "upper" "user" "variance"
2300 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2301 "action" "add" "after" "against" "all" "alter" "and" "as" "asc"
2302 "auto_increment" "avg_row_length" "bdb" "between" "by" "cascade"
2303 "case" "change" "character" "check" "checksum" "close" "collate"
2304 "collation" "column" "columns" "comment" "committed" "concurrent"
2305 "constraint" "create" "cross" "data" "database" "default"
2306 "delay_key_write" "delayed" "delete" "desc" "directory" "disable"
2307 "distinct" "distinctrow" "do" "drop" "dumpfile" "duplicate" "else" "elseif"
2308 "enable" "enclosed" "end" "escaped" "exists" "fields" "first" "for"
2309 "force" "foreign" "from" "full" "fulltext" "global" "group" "handler"
2310 "having" "heap" "high_priority" "if" "ignore" "in" "index" "infile"
2311 "inner" "insert" "insert_method" "into" "is" "isam" "isolation" "join"
2312 "key" "keys" "last" "left" "level" "like" "limit" "lines" "load"
2313 "local" "lock" "low_priority" "match" "max_rows" "merge" "min_rows"
2314 "mode" "modify" "mrg_myisam" "myisam" "natural" "next" "no" "not"
2315 "null" "offset" "oj" "on" "open" "optionally" "or" "order" "outer"
2316 "outfile" "pack_keys" "partial" "password" "prev" "primary"
2317 "procedure" "quick" "raid0" "raid_type" "read" "references" "rename"
2318 "repeatable" "restrict" "right" "rollback" "rollup" "row_format"
2319 "savepoint" "select" "separator" "serializable" "session" "set"
2320 "share" "show" "sql_big_result" "sql_buffer_result" "sql_cache"
2321 "sql_calc_found_rows" "sql_no_cache" "sql_small_result" "starting"
2322 "straight_join" "striped" "table" "tables" "temporary" "terminated"
2323 "then" "to" "transaction" "truncate" "type" "uncommitted" "union"
2324 "unique" "unlock" "update" "use" "using" "values" "when" "where"
2325 "with" "write" "xor"
2329 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2330 "bigint" "binary" "bit" "blob" "bool" "boolean" "char" "curve" "date"
2331 "datetime" "dec" "decimal" "double" "enum" "fixed" "float" "geometry"
2332 "geometrycollection" "int" "integer" "line" "linearring" "linestring"
2333 "longblob" "longtext" "mediumblob" "mediumint" "mediumtext"
2334 "multicurve" "multilinestring" "multipoint" "multipolygon"
2335 "multisurface" "national" "numeric" "point" "polygon" "precision"
2336 "real" "smallint" "surface" "text" "time" "timestamp" "tinyblob"
2337 "tinyint" "tinytext" "unsigned" "varchar" "year" "year2" "year4"
2341 "MySQL SQL keywords used by font-lock.
2343 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2344 regular expressions are created during compilation by calling the
2345 function `regexp-opt'. Therefore, take a look at the source before
2346 you define your own `sql-mode-mysql-font-lock-keywords'.")
2348 (defvar sql-mode-sqlite-font-lock-keywords
2352 '("^[.].*$" . font-lock-doc-face
)
2355 (sql-font-lock-keywords-builder 'font-lock-keyword-face nil
2356 "abort" "action" "add" "after" "all" "alter" "analyze" "and" "as"
2357 "asc" "attach" "autoincrement" "before" "begin" "between" "by"
2358 "cascade" "case" "cast" "check" "collate" "column" "commit" "conflict"
2359 "constraint" "create" "cross" "database" "default" "deferrable"
2360 "deferred" "delete" "desc" "detach" "distinct" "drop" "each" "else"
2361 "end" "escape" "except" "exclusive" "exists" "explain" "fail" "for"
2362 "foreign" "from" "full" "glob" "group" "having" "if" "ignore"
2363 "immediate" "in" "index" "indexed" "initially" "inner" "insert"
2364 "instead" "intersect" "into" "is" "isnull" "join" "key" "left" "like"
2365 "limit" "match" "natural" "no" "not" "notnull" "null" "of" "offset"
2366 "on" "or" "order" "outer" "plan" "pragma" "primary" "query" "raise"
2367 "references" "regexp" "reindex" "release" "rename" "replace"
2368 "restrict" "right" "rollback" "row" "savepoint" "select" "set" "table"
2369 "temp" "temporary" "then" "to" "transaction" "trigger" "union"
2370 "unique" "update" "using" "vacuum" "values" "view" "virtual" "when"
2373 ;; SQLite Data types
2374 (sql-font-lock-keywords-builder 'font-lock-type-face nil
2375 "int" "integer" "tinyint" "smallint" "mediumint" "bigint" "unsigned"
2376 "big" "int2" "int8" "character" "varchar" "varying" "nchar" "native"
2377 "nvarchar" "text" "clob" "blob" "real" "double" "precision" "float"
2378 "numeric" "number" "decimal" "boolean" "date" "datetime"
2381 (sql-font-lock-keywords-builder 'font-lock-builtin-face nil
2383 "abs" "changes" "coalesce" "glob" "ifnull" "hex" "last_insert_rowid"
2384 "length" "like" "load_extension" "lower" "ltrim" "max" "min" "nullif"
2385 "quote" "random" "randomblob" "replace" "round" "rtrim" "soundex"
2386 "sqlite_compileoption_get" "sqlite_compileoption_used"
2387 "sqlite_source_id" "sqlite_version" "substr" "total_changes" "trim"
2388 "typeof" "upper" "zeroblob"
2389 ;; Date/time functions
2390 "time" "julianday" "strftime"
2391 "current_date" "current_time" "current_timestamp"
2392 ;; Aggregate functions
2393 "avg" "count" "group_concat" "max" "min" "sum" "total"
2396 "SQLite SQL keywords used by font-lock.
2398 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2399 regular expressions are created during compilation by calling the
2400 function `regexp-opt'. Therefore, take a look at the source before
2401 you define your own `sql-mode-sqlite-font-lock-keywords'.")
2403 (defvar sql-mode-db2-font-lock-keywords nil
2404 "DB2 SQL keywords used by font-lock.
2406 This variable is used by `sql-mode' and `sql-interactive-mode'. The
2407 regular expressions are created during compilation by calling the
2408 function `regexp-opt'. Therefore, take a look at the source before
2409 you define your own `sql-mode-db2-font-lock-keywords'.")
2411 (defvar sql-mode-font-lock-keywords nil
2412 "SQL keywords used by font-lock.
2414 Setting this variable directly no longer has any affect. Use
2415 `sql-product' and `sql-add-product-keywords' to control the
2416 highlighting rules in SQL mode.")
2420 ;;; SQL Product support functions
2422 (defun sql-read-product (prompt &optional initial
)
2423 "Read a valid SQL product."
2424 (let ((init (or (and initial
(symbol-name initial
)) "ansi")))
2425 (intern (completing-read
2427 (mapcar (lambda (info) (symbol-name (car info
)))
2430 init
'sql-product-history init
))))
2432 (defun sql-add-product (product display
&rest plist
)
2433 "Add support for a database product in `sql-mode'.
2435 Add PRODUCT to `sql-product-alist' which enables `sql-mode' to
2436 properly support syntax highlighting and interactive interaction.
2437 DISPLAY is the name of the SQL product that will appear in the
2438 menu bar and in messages. PLIST initializes the product
2441 ;; Don't do anything if the product is already supported
2442 (if (assoc product sql-product-alist
)
2443 (message "Product `%s' is already defined" product
)
2445 ;; Add product to the alist
2446 (add-to-list 'sql-product-alist
`((,product
:name
,display .
,plist
)))
2447 ;; Add a menu item to the SQL->Product menu
2448 (easy-menu-add-item sql-mode-menu
'("Product")
2449 ;; Each product is represented by a radio
2450 ;; button with it's display name.
2452 (sql-set-product ',product
)
2454 :selected
(eq sql-product
',product
)]
2455 ;; Maintain the product list in
2456 ;; (case-insensitive) alphabetic order of the
2457 ;; display names. Loop thru each keymap item
2458 ;; looking for an item whose display name is
2459 ;; after this product's name.
2461 (down-display (downcase display
)))
2462 (map-keymap (lambda (k b
)
2463 (when (and (not next-item
)
2464 (string-lessp down-display
2465 (downcase (cadr b
))))
2466 (setq next-item k
)))
2467 (easy-menu-get-map sql-mode-menu
'("Product")))
2471 (defun sql-del-product (product)
2472 "Remove support for PRODUCT in `sql-mode'."
2474 ;; Remove the menu item based on the display name
2475 (easy-menu-remove-item sql-mode-menu
'("Product") (sql-get-product-feature product
:name
))
2476 ;; Remove the product alist item
2477 (setq sql-product-alist
(assq-delete-all product sql-product-alist
))
2480 (defun sql-set-product-feature (product feature newvalue
)
2481 "Set FEATURE of database PRODUCT to NEWVALUE.
2483 The PRODUCT must be a symbol which identifies the database
2484 product. The product must have already exist on the product
2485 list. See `sql-add-product' to add new products. The FEATURE
2486 argument must be a plist keyword accepted by
2487 `sql-product-alist'."
2489 (let* ((p (assoc product sql-product-alist
))
2490 (v (plist-get (cdr p
) feature
)))
2493 (member feature sql-indirect-features
)
2496 (setcdr p
(plist-put (cdr p
) feature newvalue
)))
2497 (message "`%s' is not a known product; use `sql-add-product' to add it first." product
))))
2499 (defun sql-get-product-feature (product feature
&optional fallback not-indirect
)
2500 "Lookup FEATURE associated with a SQL PRODUCT.
2502 If the FEATURE is nil for PRODUCT, and FALLBACK is specified,
2503 then the FEATURE associated with the FALLBACK product is
2506 If the FEATURE is in the list `sql-indirect-features', and the
2507 NOT-INDIRECT parameter is not set, then the value of the symbol
2508 stored in the connect alist is returned.
2510 See `sql-product-alist' for a list of products and supported features."
2511 (let* ((p (assoc product sql-product-alist
))
2512 (v (plist-get (cdr p
) feature
)))
2515 ;; If no value and fallback, lookup feature for fallback
2518 (not (eq product fallback
)))
2519 (sql-get-product-feature fallback feature
)
2522 (member feature sql-indirect-features
)
2527 (message "`%s' is not a known product; use `sql-add-product' to add it first." product
)
2530 (defun sql-product-font-lock (keywords-only imenu
)
2531 "Configure font-lock and imenu with product-specific settings.
2533 The KEYWORDS-ONLY flag is passed to font-lock to specify whether
2534 only keywords should be highlighted and syntactic highlighting
2535 skipped. The IMENU flag indicates whether `imenu-mode' should
2536 also be configured."
2539 ;; Get the product-specific syntax-alist.
2540 ((syntax-alist (sql-product-font-lock-syntax-alist)))
2542 ;; Get the product-specific keywords.
2543 (set (make-local-variable 'sql-mode-font-lock-keywords
)
2545 (unless (eq sql-product
'ansi
)
2546 (sql-get-product-feature sql-product
:font-lock
))
2547 ;; Always highlight ANSI keywords
2548 (sql-get-product-feature 'ansi
:font-lock
)
2549 ;; Fontify object names in CREATE, DROP and ALTER DDL
2551 (list sql-mode-font-lock-object-name
)))
2553 ;; Setup font-lock. Force re-parsing of `font-lock-defaults'.
2554 (kill-local-variable 'font-lock-set-defaults
)
2555 (set (make-local-variable 'font-lock-defaults
)
2556 (list 'sql-mode-font-lock-keywords
2557 keywords-only t syntax-alist
))
2559 ;; Force font lock to reinitialize if it is already on
2560 ;; Otherwise, we can wait until it can be started.
2561 (when (and (fboundp 'font-lock-mode
)
2562 (boundp 'font-lock-mode
)
2564 (font-lock-mode-internal nil
)
2565 (font-lock-mode-internal t
))
2567 (add-hook 'font-lock-mode-hook
2569 ;; Provide defaults for new font-lock faces.
2570 (defvar font-lock-builtin-face
2571 (if (boundp 'font-lock-preprocessor-face
)
2572 font-lock-preprocessor-face
2573 font-lock-keyword-face
))
2574 (defvar font-lock-doc-face font-lock-string-face
))
2577 ;; Setup imenu; it needs the same syntax-alist.
2579 (setq imenu-syntax-alist syntax-alist
))))
2582 (defun sql-add-product-keywords (product keywords
&optional append
)
2583 "Add highlighting KEYWORDS for SQL PRODUCT.
2585 PRODUCT should be a symbol, the name of a SQL product, such as
2586 `oracle'. KEYWORDS should be a list; see the variable
2587 `font-lock-keywords'. By default they are added at the beginning
2588 of the current highlighting list. If optional argument APPEND is
2589 `set', they are used to replace the current highlighting list.
2590 If APPEND is any other non-nil value, they are added at the end
2591 of the current highlighting list.
2595 (sql-add-product-keywords 'ms
2596 '((\"\\\\b\\\\w+_t\\\\b\" . font-lock-type-face)))
2598 adds a fontification pattern to fontify identifiers ending in
2599 `_t' as data types."
2601 (let* ((sql-indirect-features nil
)
2602 (font-lock-var (sql-get-product-feature product
:font-lock
))
2605 (setq old-val
(symbol-value font-lock-var
))
2607 (if (eq append
'set
)
2610 (append old-val keywords
)
2611 (append keywords old-val
))))))
2613 (defun sql-for-each-login (login-params body
)
2614 "Iterates through login parameters and returns a list of results."
2619 (let ((token (or (and (listp param
) (car param
)) param
))
2620 (plist (or (and (listp param
) (cdr param
)) nil
)))
2622 (funcall body token plist
)))
2627 ;;; Functions to switch highlighting
2629 (defun sql-product-syntax-table ()
2630 (let ((table (copy-syntax-table sql-mode-syntax-table
)))
2631 (mapc (lambda (entry)
2632 (modify-syntax-entry (car entry
) (cdr entry
) table
))
2633 (sql-get-product-feature sql-product
:syntax-alist
))
2636 (defun sql-product-font-lock-syntax-alist ()
2638 ;; Change all symbol character to word characters
2640 (lambda (entry) (if (string= (substring (cdr entry
) 0 1) "_")
2642 (concat "w" (substring (cdr entry
) 1)))
2644 (sql-get-product-feature sql-product
:syntax-alist
))
2647 (defun sql-highlight-product ()
2648 "Turn on the font highlighting for the SQL product selected."
2649 (when (derived-mode-p 'sql-mode
)
2650 ;; Enhance the syntax table for the product
2651 (set-syntax-table (sql-product-syntax-table))
2654 (sql-product-font-lock nil t
)
2656 ;; Set the mode name to include the product.
2657 (setq mode-name
(concat "SQL[" (or (sql-get-product-feature sql-product
:name
)
2658 (symbol-name sql-product
)) "]"))))
2660 (defun sql-set-product (product)
2661 "Set `sql-product' to PRODUCT and enable appropriate highlighting."
2663 (list (sql-read-product "SQL product: ")))
2664 (if (stringp product
) (setq product
(intern product
)))
2665 (when (not (assoc product sql-product-alist
))
2666 (error "SQL product %s is not supported; treated as ANSI" product
)
2667 (setq product
'ansi
))
2669 ;; Save product setting and fontify.
2670 (setq sql-product product
)
2671 (sql-highlight-product))
2674 ;;; Compatibility functions
2676 (if (not (fboundp 'comint-line-beginning-position
))
2677 ;; comint-line-beginning-position is defined in Emacs 21
2678 (defun comint-line-beginning-position ()
2679 "Return the buffer position of the beginning of the line, after any prompt.
2680 The prompt is assumed to be any text at the beginning of the line
2681 matching the regular expression `comint-prompt-regexp', a buffer
2683 (save-excursion (comint-bol nil
) (point))))
2685 ;;; Motion Functions
2687 (defun sql-statement-regexp (prod)
2688 (let* ((ansi-stmt (sql-get-product-feature 'ansi
:statement
))
2689 (prod-stmt (sql-get-product-feature prod
:statement
)))
2693 (concat "\\(" ansi-stmt
"\\|" prod-stmt
"\\)"))
2696 (defun sql-beginning-of-statement (arg)
2697 "Moves the cursor to the beginning of the current SQL statement."
2700 (let ((here (point))
2701 (regexp (sql-statement-regexp sql-product
))
2704 ;; Go to the end of the statement before the start we desire
2705 (setq last
(or (sql-end-of-statement (- arg
))
2707 ;; And find the end after that
2708 (setq next
(or (sql-end-of-statement 1)
2711 ;; Our start must be between them
2713 ;; Find an beginning-of-stmt that's not in a comment
2714 (while (and (re-search-forward regexp next t
1)
2715 (nth 7 (syntax-ppss)))
2716 (goto-char (match-end 0)))
2722 ;; If we didn't move, try again
2723 (when (= here
(point))
2724 (sql-beginning-of-statement (* 2 (sql-signum arg
))))))
2726 (defun sql-end-of-statement (arg)
2727 "Moves the cursor to the end of the current SQL statement."
2729 (let ((term (sql-get-product-feature sql-product
:terminator
))
2730 (re-search (if (> 0 arg
) 're-search-backward
're-search-forward
))
2734 (setq term
(car term
)))
2735 ;; Iterate until we've moved the desired number of stmt ends
2736 (while (not (= (sql-signum arg
) 0))
2737 ;; if we're looking at the terminator, jump by 2
2738 (if (or (and (> 0 arg
) (looking-back term
))
2739 (and (< 0 arg
) (looking-at term
)))
2742 ;; If we found another end-of-stmt
2743 (if (not (apply re-search term nil t n nil
))
2745 ;; count it if we're not in a comment
2746 (unless (nth 7 (syntax-ppss))
2747 (setq arg
(- arg
(sql-signum arg
))))))
2748 (goto-char (if (match-data)
2754 (defun sql-magic-go (arg)
2755 "Insert \"o\" and call `comint-send-input'.
2756 `sql-electric-stuff' must be the symbol `go'."
2758 (self-insert-command (prefix-numeric-value arg
))
2759 (if (and (equal sql-electric-stuff
'go
)
2762 (looking-at "go\\b")))
2763 (comint-send-input)))
2765 (defun sql-magic-semicolon (arg)
2766 "Insert semicolon and call `comint-send-input'.
2767 `sql-electric-stuff' must be the symbol `semicolon'."
2769 (self-insert-command (prefix-numeric-value arg
))
2770 (if (equal sql-electric-stuff
'semicolon
)
2771 (comint-send-input)))
2773 (defun sql-accumulate-and-indent ()
2774 "Continue SQL statement on the next line."
2776 (if (fboundp 'comint-accumulate
)
2779 (indent-according-to-mode))
2781 (defun sql-help-list-products (indent freep
)
2782 "Generate listing of products available for use under SQLi.
2784 List products with :free-software attribute set to FREEP. Indent
2785 each line with INDENT."
2787 (let (sqli-func doc
)
2789 (dolist (p sql-product-alist
)
2790 (setq sqli-func
(intern (concat "sql-" (symbol-name (car p
)))))
2792 (if (and (fboundp sqli-func
)
2793 (eq (sql-get-product-feature (car p
) :free-software
) freep
))
2797 (or (sql-get-product-feature (car p
) :name
)
2798 (symbol-name (car p
)))
2801 (symbol-name sqli-func
)
2807 ;; FIXME: This dynamic-docstring-function trick doesn't work for byte-compiled
2808 ;; functions, because of the lazy-loading of docstrings, which strips away
2811 #("Show short help for the SQL modes.
2813 Use an entry function to open an interactive SQL buffer. This buffer is
2814 usually named `*SQL*'. The name of the major mode is SQLi.
2816 Use the following commands to start a specific SQL interpreter:
2820 Other non-free SQL implementations are also supported:
2824 But we urge you to choose a free implementation instead of these.
2826 You can also use \\[sql-product-interactive] to invoke the
2827 interpreter for the current `sql-product'.
2829 Once you have the SQLi buffer, you can enter SQL statements in the
2830 buffer. The output generated is appended to the buffer and a new prompt
2831 is generated. See the In/Out menu in the SQLi buffer for some functions
2832 that help you navigate through the buffer, the input history, etc.
2834 If you have a really complex SQL statement or if you are writing a
2835 procedure, you can do this in a separate buffer. Put the new buffer in
2836 `sql-mode' by calling \\[sql-mode]. The name of this buffer can be
2837 anything. The name of the major mode is SQL.
2839 In this SQL buffer (SQL mode), you can send the region or the entire
2840 buffer to the interactive SQL buffer (SQLi mode). The results are
2841 appended to the SQLi buffer without disturbing your SQL buffer."
2842 0 1 (dynamic-docstring-function sql--make-help-docstring
))
2844 (describe-function 'sql-help
)))
2846 (defun sql--make-help-docstring (doc _fun
)
2847 "Insert references to loaded products into the help buffer string."
2849 ;; Insert FREE software list
2850 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]FREE\\s-*\n" doc
0)
2851 (setq doc
(replace-match (sql-help-list-products (match-string 1 doc
) t
)
2854 ;; Insert non-FREE software list
2855 (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]NONFREE\\s-*\n" doc
0)
2856 (setq doc
(replace-match (sql-help-list-products (match-string 1 doc
) nil
)
2860 (defun sql-read-passwd (prompt &optional default
)
2861 "Read a password using PROMPT. Optional DEFAULT is password to start with."
2862 (read-passwd prompt nil default
))
2864 (defun sql-get-login-ext (symbol prompt history-var plist
)
2865 "Prompt user with extended login parameters.
2867 The global value of SYMBOL is the last value and the global value
2868 of the SYMBOL is set based on the user's input.
2870 If PLIST is nil, then the user is simply prompted for a string
2873 The property `:default' specifies the default value. If the
2874 `:number' property is non-nil then ask for a number.
2876 The `:file' property prompts for a file name that must match the
2877 regexp pattern specified in its value.
2879 The `:completion' property prompts for a string specified by its
2880 value. (The property value is used as the PREDICATE argument to
2881 `completing-read'.)"
2884 (let* ((default (plist-get plist
:default
))
2885 (last-value (default-value symbol
))
2888 (if (string-match "\\(\\):[ \t]*\\'" prompt
)
2889 (replace-match (format " (default \"%s\")" default
) t t prompt
1)
2890 (replace-regexp-in-string "[ \t]*\\'"
2891 (format " (default \"%s\") " default
)
2894 (use-dialog-box nil
))
2896 ((plist-member plist
:file
)
2898 (read-file-name prompt
2899 (file-name-directory last-value
) default t
2900 (file-name-nondirectory last-value
)
2901 (when (plist-get plist
:file
)
2904 (concat "\\<" ,(plist-get plist
:file
) "\\>")
2905 (file-name-nondirectory f
)))))))
2907 ((plist-member plist
:completion
)
2908 (completing-read prompt-def
(plist-get plist
:completion
) nil t
2909 last-value history-var default
))
2911 ((plist-get plist
:number
)
2912 (read-number prompt
(or default last-value
0)))
2915 (let ((r (read-from-minibuffer prompt-def last-value nil nil history-var nil
)))
2916 (if (string= "" r
) (or default
"") r
)))))))
2918 (defun sql-get-login (&rest what
)
2919 "Get username, password and database from the user.
2921 The variables `sql-user', `sql-password', `sql-server', and
2922 `sql-database' can be customized. They are used as the default values.
2923 Usernames, servers and databases are stored in `sql-user-history',
2924 `sql-server-history' and `database-history'. Passwords are not stored
2927 Parameter WHAT is a list of tokens passed as arguments in the
2928 function call. The function asks for the username if WHAT
2929 contains the symbol `user', for the password if it contains the
2930 symbol `password', for the server if it contains the symbol
2931 `server', and for the database if it contains the symbol
2932 `database'. The members of WHAT are processed in the order in
2933 which they are provided.
2935 Each token may also be a list with the token in the car and a
2936 plist of options as the cdr. The following properties are
2939 :file <filename-regexp>
2940 :completion <list-of-strings-or-function>
2941 :default <default-value>
2944 In order to ask the user for username, password and database, call the
2945 function like this: (sql-get-login 'user 'password 'database)."
2949 (let ((token (or (and (consp w
) (car w
)) w
))
2950 (plist (or (and (consp w
) (cdr w
)) nil
)))
2953 ((eq token
'user
) ; user
2954 (sql-get-login-ext 'sql-user
"User: " 'sql-user-history plist
))
2956 ((eq token
'password
) ; password
2957 (setq-default sql-password
2958 (sql-read-passwd "Password: " sql-password
)))
2960 ((eq token
'server
) ; server
2961 (sql-get-login-ext 'sql-server
"Server: " 'sql-server-history plist
))
2963 ((eq token
'database
) ; database
2964 (sql-get-login-ext 'sql-database
"Database: " 'sql-database-history plist
))
2966 ((eq token
'port
) ; port
2967 (sql-get-login-ext 'sql-port
"Port: " nil
(append '(:number t
) plist
))))))
2970 (defun sql-find-sqli-buffer (&optional product connection
)
2971 "Returns the name of the current default SQLi buffer or nil.
2972 In order to qualify, the SQLi buffer must be alive, be in
2973 `sql-interactive-mode' and have a process."
2974 (let ((buf sql-buffer
)
2975 (prod (or product sql-product
)))
2977 ;; Current sql-buffer, if there is one.
2978 (and (sql-buffer-live-p buf prod connection
)
2980 ;; Global sql-buffer
2981 (and (setq buf
(default-value 'sql-buffer
))
2982 (sql-buffer-live-p buf prod connection
)
2984 ;; Look thru each buffer
2987 (and (sql-buffer-live-p b prod connection
)
2988 (list (buffer-name b
))))
2991 (defun sql-set-sqli-buffer-generally ()
2992 "Set SQLi buffer for all SQL buffers that have none.
2993 This function checks all SQL buffers for their SQLi buffer. If their
2994 SQLi buffer is nonexistent or has no process, it is set to the current
2995 default SQLi buffer. The current default SQLi buffer is determined
2996 using `sql-find-sqli-buffer'. If `sql-buffer' is set,
2997 `sql-set-sqli-hook' is run."
3000 (let ((buflist (buffer-list))
3001 (default-buffer (sql-find-sqli-buffer)))
3002 (setq-default sql-buffer default-buffer
)
3003 (while (not (null buflist
))
3004 (let ((candidate (car buflist
)))
3005 (set-buffer candidate
)
3006 (if (and (derived-mode-p 'sql-mode
)
3007 (not (sql-buffer-live-p sql-buffer
)))
3009 (setq sql-buffer default-buffer
)
3010 (when default-buffer
3011 (run-hooks 'sql-set-sqli-hook
)))))
3012 (setq buflist
(cdr buflist
))))))
3014 (defun sql-set-sqli-buffer ()
3015 "Set the SQLi buffer SQL strings are sent to.
3017 Call this function in a SQL buffer in order to set the SQLi buffer SQL
3018 strings are sent to. Calling this function sets `sql-buffer' and runs
3019 `sql-set-sqli-hook'.
3021 If you call it from a SQL buffer, this sets the local copy of
3024 If you call it from anywhere else, it sets the global copy of
3027 (let ((default-buffer (sql-find-sqli-buffer)))
3028 (if (null default-buffer
)
3029 (error "There is no suitable SQLi buffer")
3030 (let ((new-buffer (read-buffer "New SQLi buffer: " default-buffer t
)))
3031 (if (null (sql-buffer-live-p new-buffer
))
3032 (error "Buffer %s is not a working SQLi buffer" new-buffer
)
3034 (setq sql-buffer new-buffer
)
3035 (run-hooks 'sql-set-sqli-hook
)))))))
3037 (defun sql-show-sqli-buffer ()
3038 "Show the name of current SQLi buffer.
3040 This is the buffer SQL strings are sent to. It is stored in the
3041 variable `sql-buffer'. See `sql-help' on how to create such a buffer."
3043 (if (or (null sql-buffer
)
3044 (null (buffer-live-p (get-buffer sql-buffer
))))
3045 (message "%s has no SQLi buffer set." (buffer-name (current-buffer)))
3046 (if (null (get-buffer-process sql-buffer
))
3047 (message "Buffer %s has no process." sql-buffer
)
3048 (message "Current SQLi buffer is %s." sql-buffer
))))
3050 (defun sql-make-alternate-buffer-name ()
3051 "Return a string that can be used to rename a SQLi buffer.
3053 This is used to set `sql-alternate-buffer-name' within
3054 `sql-interactive-mode'.
3056 If the session was started with `sql-connect' then the alternate
3057 name would be the name of the connection.
3059 Otherwise, it uses the parameters identified by the :sqlilogin
3062 If all else fails, the alternate name would be the user and
3063 server/database name."
3067 ;; Build a name using the :sqli-login setting
3073 (sql-get-product-feature sql-product
:sqli-login
)
3074 (lambda (token plist
)
3077 (unless (string= "" sql-user
)
3078 (list "/" sql-user
)))
3080 (unless (or (not (numberp sql-port
))
3082 (list ":" (number-to-string sql-port
))))
3084 (unless (string= "" sql-server
)
3086 (if (plist-member plist
:file
)
3087 (file-name-nondirectory sql-server
)
3089 ((eq token
'database
)
3090 (unless (string= "" sql-database
)
3092 (if (plist-member plist
:file
)
3093 (file-name-nondirectory sql-database
)
3096 ((eq token
'password
) nil
)
3099 ;; If there's a connection, use it and the name thus far
3101 (format "<%s>%s" sql-connection
(or name
""))
3103 ;; If there is no name, try to create something meaningful
3104 (if (string= "" (or name
""))
3106 (if (string= "" sql-user
)
3107 (if (string= "" (user-login-name))
3109 (concat (user-login-name) "/"))
3110 (concat sql-user
"/"))
3111 (if (string= "" sql-database
)
3112 (if (string= "" sql-server
)
3117 ;; Use the name we've got
3120 (defun sql-rename-buffer (&optional new-name
)
3121 "Rename a SQL interactive buffer.
3123 Prompts for the new name if command is preceded by
3124 \\[universal-argument]. If no buffer name is provided, then the
3125 `sql-alternate-buffer-name' is used.
3127 The actual buffer name set will be \"*SQL: NEW-NAME*\". If
3128 NEW-NAME is empty, then the buffer name will be \"*SQL*\"."
3131 (if (not (derived-mode-p 'sql-interactive-mode
))
3132 (message "Current buffer is not a SQL interactive buffer")
3134 (setq sql-alternate-buffer-name
3136 ((stringp new-name
) new-name
)
3138 (read-string "Buffer name (\"*SQL: XXX*\"; enter `XXX'): "
3139 sql-alternate-buffer-name
))
3140 (t sql-alternate-buffer-name
)))
3142 (rename-buffer (if (string= "" sql-alternate-buffer-name
)
3144 (format "*SQL: %s*" sql-alternate-buffer-name
))
3147 (defun sql-copy-column ()
3148 "Copy current column to the end of buffer.
3149 Inserts SELECT or commas if appropriate."
3153 (setq column
(buffer-substring-no-properties
3154 (progn (forward-char 1) (backward-sexp 1) (point))
3155 (progn (forward-sexp 1) (point))))
3156 (goto-char (point-max))
3157 (let ((bol (comint-line-beginning-position)))
3159 ;; if empty command line, insert SELECT
3162 ;; else if appending to INTO .* (, SELECT or ORDER BY, insert a comma
3164 (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+"
3167 ;; else insert a space
3169 (if (eq (preceding-char) ?\s
)
3172 ;; in any case, insert the column
3174 (message "%s" column
))))
3176 ;; On Windows, SQL*Plus for Oracle turns on full buffering for stdout
3177 ;; if it is not attached to a character device; therefore placeholder
3178 ;; replacement by SQL*Plus is fully buffered. The workaround lets
3179 ;; Emacs query for the placeholders.
3181 (defvar sql-placeholder-history nil
3182 "History of placeholder values used.")
3184 (defun sql-placeholders-filter (string)
3185 "Replace placeholders in STRING.
3186 Placeholders are words starting with an ampersand like &this."
3188 (when sql-oracle-scan-on
3189 (while (string-match "&\\(\\sw+\\)" string
)
3190 (setq string
(replace-match
3191 (read-from-minibuffer
3192 (format "Enter value for %s: " (match-string 1 string
))
3193 nil nil nil
'sql-placeholder-history
)
3197 ;; Using DB2 interactively, newlines must be escaped with " \".
3198 ;; The space before the backslash is relevant.
3200 (defun sql-escape-newlines-filter (string)
3201 "Escape newlines in STRING.
3202 Every newline in STRING will be preceded with a space and a backslash."
3203 (if (not sql-db2-escape-newlines
)
3205 (let ((result "") (start 0) mb me
)
3206 (while (string-match "\n" string start
)
3207 (setq mb
(match-beginning 0)
3209 result
(concat result
3210 (substring string start mb
)
3212 (string-equal " \\" (substring string
(- mb
2) mb
)))
3215 (concat result
(substring string start
)))))
3219 ;;; Input sender for SQLi buffers
3221 (defvar sql-output-newline-count
0
3222 "Number of newlines in the input string.
3224 Allows the suppression of continuation prompts.")
3226 (defvar sql-output-by-send nil
3227 "Non-nil if the command in the input was generated by `sql-send-string'.")
3229 (defun sql-input-sender (proc string
)
3230 "Send STRING to PROC after applying filters."
3232 (let* ((product (with-current-buffer (process-buffer proc
) sql-product
))
3233 (filter (sql-get-product-feature product
:input-filter
)))
3240 (setq string
(funcall filter string
)))
3242 (mapc (lambda (f) (setq string
(funcall f string
))) filter
))
3245 ;; Count how many newlines in the string
3246 (setq sql-output-newline-count
0)
3249 (setq sql-output-newline-count
(1+ sql-output-newline-count
))))
3253 (comint-simple-send proc string
)))
3255 ;;; Strip out continuation prompts
3257 (defvar sql-preoutput-hold nil
)
3259 (defun sql-interactive-remove-continuation-prompt (oline)
3260 "Strip out continuation prompts out of the OLINE.
3262 Added to the `comint-preoutput-filter-functions' hook in a SQL
3263 interactive buffer. If `sql-output-newline-count' is greater than
3264 zero, then an output line matching the continuation prompt is filtered
3265 out. If the count is zero, then a newline is inserted into the output
3266 to force the output from the query to appear on a new line.
3268 The complication to this filter is that the continuation prompts
3269 may arrive in multiple chunks. If they do, then the function
3270 saves any unfiltered output in a buffer and prepends that buffer
3271 to the next chunk to properly match the broken-up prompt.
3273 If the filter gets confused, it should reset and stop filtering
3274 to avoid deleting non-prompt output."
3277 (setq oline
(concat (or sql-preoutput-hold
"") oline
)
3278 sql-preoutput-hold nil
)
3280 (if (and comint-prompt-regexp
3281 (integerp sql-output-newline-count
)
3282 (>= sql-output-newline-count
1))
3284 (while (and (not (string= oline
""))
3285 (> sql-output-newline-count
0)
3286 (string-match comint-prompt-regexp oline
)
3287 (= (match-beginning 0) 0))
3289 (setq oline
(replace-match "" nil nil oline
)
3290 sql-output-newline-count
(1- sql-output-newline-count
)
3293 (if (= sql-output-newline-count
0)
3294 (setq sql-output-newline-count nil
3295 oline
(concat "\n" oline
)
3296 sql-output-by-send nil
)
3298 (setq sql-preoutput-hold oline
3302 (setq oline
(or sql-preoutput-hold
"")
3303 sql-preoutput-hold nil
3304 sql-output-newline-count nil
)))
3306 (setq sql-output-newline-count nil
))
3310 ;;; Sending the region to the SQLi buffer.
3312 (defun sql-send-string (str)
3313 "Send the string STR to the SQL process."
3314 (interactive "sSQL Text: ")
3316 (let ((comint-input-sender-no-newline nil
)
3317 (s (replace-regexp-in-string "[[:space:]\n\r]+\\'" "" str
)))
3318 (if (sql-buffer-live-p sql-buffer
)
3320 ;; Ignore the hoping around...
3322 ;; Set product context
3323 (with-current-buffer sql-buffer
3324 ;; Send the string (trim the trailing whitespace)
3325 (sql-input-sender (get-buffer-process sql-buffer
) s
)
3327 ;; Send a command terminator if we must
3328 (if sql-send-terminator
3329 (sql-send-magic-terminator sql-buffer s sql-send-terminator
))
3331 (message "Sent string to buffer %s." sql-buffer
)))
3333 ;; Display the sql buffer
3334 (if sql-pop-to-buffer-after-send-region
3335 (pop-to-buffer sql-buffer
)
3336 (display-buffer sql-buffer
)))
3338 ;; We don't have no stinkin' sql
3339 (message "No SQL process started."))))
3341 (defun sql-send-region (start end
)
3342 "Send a region to the SQL process."
3344 (sql-send-string (buffer-substring-no-properties start end
)))
3346 (defun sql-send-paragraph ()
3347 "Send the current paragraph to the SQL process."
3349 (let ((start (save-excursion
3350 (backward-paragraph)
3352 (end (save-excursion
3355 (sql-send-region start end
)))
3357 (defun sql-send-buffer ()
3358 "Send the buffer contents to the SQL process."
3360 (sql-send-region (point-min) (point-max)))
3362 (defun sql-send-magic-terminator (buf str terminator
)
3363 "Send TERMINATOR to buffer BUF if its not present in STR."
3364 (let (comint-input-sender-no-newline pat term
)
3365 ;; If flag is merely on(t), get product-specific terminator
3366 (if (eq terminator t
)
3367 (setq terminator
(sql-get-product-feature sql-product
:terminator
)))
3369 ;; If there is no terminator specified, use default ";"
3371 (setq terminator
";"))
3373 ;; Parse the setting into the pattern and the terminator string
3374 (cond ((stringp terminator
)
3375 (setq pat
(regexp-quote terminator
)
3378 (setq pat
(car terminator
)
3379 term
(cdr terminator
)))
3383 ;; Check to see if the pattern is present in the str already sent
3384 (unless (and pat term
3385 (string-match (concat pat
"\\'") str
))
3386 (comint-simple-send (get-buffer-process buf
) term
)
3387 (setq sql-output-newline-count
3388 (if sql-output-newline-count
3389 (1+ sql-output-newline-count
)
3391 (setq sql-output-by-send t
)))
3393 (defun sql-remove-tabs-filter (str)
3394 "Replace tab characters with spaces."
3395 (replace-regexp-in-string "\t" " " str nil t
))
3397 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value
)
3398 "Toggle `sql-pop-to-buffer-after-send-region'.
3400 If given the optional parameter VALUE, sets
3401 `sql-toggle-pop-to-buffer-after-send-region' to VALUE."
3404 (setq sql-pop-to-buffer-after-send-region value
)
3405 (setq sql-pop-to-buffer-after-send-region
3406 (null sql-pop-to-buffer-after-send-region
))))
3410 ;;; Redirect output functions
3412 (defvar sql-debug-redirect nil
3413 "If non-nil, display messages related to the use of redirection.")
3415 (defun sql-str-literal (s)
3416 (concat "'" (replace-regexp-in-string "[']" "''" s
) "'"))
3418 (defun sql-redirect (sqlbuf command
&optional outbuf save-prior
)
3419 "Execute the SQL command and send output to OUTBUF.
3421 SQLBUF must be an active SQL interactive buffer. OUTBUF may be
3422 an existing buffer, or the name of a non-existing buffer. If
3423 omitted the output is sent to a temporary buffer which will be
3424 killed after the command completes. COMMAND should be a string
3425 of commands accepted by the SQLi program. COMMAND may also be a
3426 list of SQLi command strings."
3428 (let* ((visible (and outbuf
3429 (not (string= " " (substring outbuf
0 1))))))
3431 (message "Executing SQL command..."))
3433 (mapc (lambda (c) (sql-redirect-one sqlbuf c outbuf save-prior
))
3435 (sql-redirect-one sqlbuf command outbuf save-prior
))
3437 (message "Executing SQL command...done"))))
3439 (defun sql-redirect-one (sqlbuf command outbuf save-prior
)
3440 (with-current-buffer sqlbuf
3441 (let ((buf (get-buffer-create (or outbuf
" *SQL-Redirect*")))
3442 (proc (get-buffer-process (current-buffer)))
3443 (comint-prompt-regexp (sql-get-product-feature sql-product
3446 (with-current-buffer buf
3447 (setq view-read-only nil
)
3450 (goto-char (point-max))
3451 (unless (zerop (buffer-size))
3453 (setq start
(point)))
3455 (when sql-debug-redirect
3456 (message ">>SQL> %S" command
))
3459 (comint-redirect-send-command-to-process command buf proc nil t
)
3460 (while (null comint-redirect-completed
)
3461 (accept-process-output nil
1))
3463 ;; Clean up the output results
3464 (with-current-buffer buf
3465 ;; Remove trailing whitespace
3466 (goto-char (point-max))
3467 (when (looking-back "[ \t\f\n\r]*" start
)
3468 (delete-region (match-beginning 0) (match-end 0)))
3469 ;; Remove echo if there was one
3471 (when (looking-at (concat "^" (regexp-quote command
) "[\\n]"))
3472 (delete-region (match-beginning 0) (match-end 0)))
3475 (while (re-search-forward "\r+$" nil t
)
3476 (replace-match "" t t
))
3477 (goto-char start
)))))
3479 (defun sql-redirect-value (sqlbuf command regexp
&optional regexp-groups
)
3480 "Execute the SQL command and return part of result.
3482 SQLBUF must be an active SQL interactive buffer. COMMAND should
3483 be a string of commands accepted by the SQLi program. From the
3484 output, the REGEXP is repeatedly matched and the list of
3485 REGEXP-GROUPS submatches is returned. This behaves much like
3486 \\[comint-redirect-results-list-from-process] but instead of
3487 returning a single submatch it returns a list of each submatch
3490 (let ((outbuf " *SQL-Redirect-values*")
3492 (sql-redirect sqlbuf command outbuf nil
)
3493 (with-current-buffer outbuf
3494 (while (re-search-forward regexp nil t
)
3497 ;; no groups-return all of them
3498 ((null regexp-groups
)
3499 (let ((i (/ (length (match-data)) 2))
3503 (push (match-string i
) r
))
3505 ;; one group specified
3506 ((numberp regexp-groups
)
3507 (match-string regexp-groups
))
3508 ;; list of numbers; return the specified matches only
3509 ((consp regexp-groups
)
3512 ((numberp c
) (match-string c
))
3513 ((stringp c
) (match-substitute-replacement c
))
3514 (t (error "sql-redirect-value: unknown REGEXP-GROUPS value - %s" c
))))
3516 ;; String is specified; return replacement string
3517 ((stringp regexp-groups
)
3518 (match-substitute-replacement regexp-groups
))
3520 (error "sql-redirect-value: unknown REGEXP-GROUPS value - %s"
3524 (when sql-debug-redirect
3525 (message ">>SQL> = %S" (reverse results
)))
3527 (nreverse results
)))
3529 (defun sql-execute (sqlbuf outbuf command enhanced arg
)
3530 "Executes a command in a SQL interactive buffer and captures the output.
3532 The commands are run in SQLBUF and the output saved in OUTBUF.
3533 COMMAND must be a string, a function or a list of such elements.
3534 Functions are called with SQLBUF, OUTBUF and ARG as parameters;
3535 strings are formatted with ARG and executed.
3537 If the results are empty the OUTBUF is deleted, otherwise the
3538 buffer is popped into a view window. "
3543 (sql-redirect sqlbuf
(if arg
(format c arg
) c
) outbuf
) t
)
3545 (apply c sqlbuf outbuf enhanced arg nil
))
3546 (t (error "Unknown sql-execute item %s" c
))))
3547 (if (consp command
) command
(cons command nil
)))
3549 (setq outbuf
(get-buffer outbuf
))
3550 (if (zerop (buffer-size outbuf
))
3551 (kill-buffer outbuf
)
3552 (let ((one-win (eq (selected-window)
3554 (with-current-buffer outbuf
3555 (set-buffer-modified-p nil
)
3556 (setq view-read-only t
))
3557 (view-buffer-other-window outbuf
)
3559 (shrink-window-if-larger-than-buffer)))))
3561 (defun sql-execute-feature (sqlbuf outbuf feature enhanced arg
)
3562 "List objects or details in a separate display buffer."
3564 (with-current-buffer sqlbuf
3565 (setq command
(sql-get-product-feature sql-product feature
)))
3567 (error "%s does not support %s" sql-product feature
))
3568 (when (consp command
)
3569 (setq command
(if enhanced
3572 (sql-execute sqlbuf outbuf command enhanced arg
)))
3574 (defvar sql-completion-object nil
3575 "A list of database objects used for completion.
3577 The list is maintained in SQL interactive buffers.")
3579 (defvar sql-completion-column nil
3580 "A list of column names used for completion.
3582 The list is maintained in SQL interactive buffers.")
3584 (defun sql-build-completions-1 (schema completion-list feature
)
3585 "Generate a list of objects in the database for use as completions."
3586 (let ((f (sql-get-product-feature sql-product feature
)))
3588 (set completion-list
3590 (dolist (e (append (symbol-value completion-list
)
3591 (apply f
(current-buffer) (cons schema nil
)))
3593 (unless (member e cl
) (setq cl
(cons e cl
))))
3594 (sort cl
(function string
<)))))))
3596 (defun sql-build-completions (schema)
3597 "Generate a list of names in the database for use as completions."
3598 (sql-build-completions-1 schema
'sql-completion-object
:completion-object
)
3599 (sql-build-completions-1 schema
'sql-completion-column
:completion-column
))
3601 (defvar sql-completion-sqlbuf nil
)
3603 (defun sql-try-completion (string collection
&optional predicate
)
3604 (when sql-completion-sqlbuf
3605 (with-current-buffer sql-completion-sqlbuf
3606 (let ((schema (and (string-match "\\`\\(\\sw\\(:?\\sw\\|\\s_\\)*\\)[.]" string
)
3607 (downcase (match-string 1 string
)))))
3609 ;; If we haven't loaded any object name yet, load local schema
3610 (unless sql-completion-object
3611 (sql-build-completions nil
))
3613 ;; If they want another schema, load it if we haven't yet
3615 (let ((schema-dot (concat schema
"."))
3616 (schema-len (1+ (length schema
)))
3617 (names sql-completion-object
)
3620 (while (and (not has-schema
) names
)
3621 (setq has-schema
(and
3622 (>= (length (car names
)) schema-len
)
3624 (downcase (substring (car names
)
3628 (sql-build-completions schema
)))))
3630 ;; Try to find the completion
3633 (try-completion string sql-completion-object
))
3635 (all-completions string sql-completion-object
))
3636 ((eq predicate
'lambda
)
3637 (test-completion string sql-completion-object
))
3638 ((eq (car predicate
) 'boundaries
)
3639 (completion-boundaries string sql-completion-object nil
(cdr predicate
)))))))
3641 (defun sql-read-table-name (prompt)
3642 "Read the name of a database table."
3644 (and (buffer-local-value 'sql-contains-names
(current-buffer))
3645 (thing-at-point-looking-at
3646 (concat "\\_<\\sw\\(:?\\sw\\|\\s_\\)*"
3647 "\\(?:[.]+\\sw\\(?:\\sw\\|\\s_\\)*\\)*\\_>"))
3648 (buffer-substring-no-properties (match-beginning 0)
3650 (sql-completion-sqlbuf (sql-find-sqli-buffer))
3651 (product (with-current-buffer sql-completion-sqlbuf sql-product
))
3652 (completion-ignore-case t
))
3654 (if (sql-get-product-feature product
:completion-object
)
3655 (completing-read prompt
(function sql-try-completion
)
3657 (read-from-minibuffer prompt tname
))))
3659 (defun sql-list-all (&optional enhanced
)
3660 "List all database objects.
3661 With optional prefix argument ENHANCED, displays additional
3662 details or extends the listing to include other schemas objects."
3664 (let ((sqlbuf (sql-find-sqli-buffer)))
3666 (error "No SQL interactive buffer found"))
3667 (sql-execute-feature sqlbuf
"*List All*" :list-all enhanced nil
)
3668 (with-current-buffer sqlbuf
3669 ;; Contains the name of database objects
3670 (set (make-local-variable 'sql-contains-names
) t
)
3671 (set (make-local-variable 'sql-buffer
) sqlbuf
))))
3673 (defun sql-list-table (name &optional enhanced
)
3674 "List the details of a database table named NAME.
3675 Displays the columns in the relation. With optional prefix argument
3676 ENHANCED, displays additional details about each column."
3678 (list (sql-read-table-name "Table name: ")
3679 current-prefix-arg
))
3680 (let ((sqlbuf (sql-find-sqli-buffer)))
3682 (error "No SQL interactive buffer found"))
3684 (error "No table name specified"))
3685 (sql-execute-feature sqlbuf
(format "*List %s*" name
)
3686 :list-table enhanced name
)))
3689 ;;; SQL mode -- uses SQL interactive mode
3692 (define-derived-mode sql-mode prog-mode
"SQL"
3693 "Major mode to edit SQL.
3695 You can send SQL statements to the SQLi buffer using
3696 \\[sql-send-region]. Such a buffer must exist before you can do this.
3697 See `sql-help' on how to create SQLi buffers.
3700 Customization: Entry to this mode runs the `sql-mode-hook'.
3702 When you put a buffer in SQL mode, the buffer stores the last SQLi
3703 buffer created as its destination in the variable `sql-buffer'. This
3704 will be the buffer \\[sql-send-region] sends the region to. If this
3705 SQLi buffer is killed, \\[sql-send-region] is no longer able to
3706 determine where the strings should be sent to. You can set the
3707 value of `sql-buffer' using \\[sql-set-sqli-buffer].
3709 For information on how to create multiple SQLi buffers, see
3710 `sql-interactive-mode'.
3712 Note that SQL doesn't have an escape character unless you specify
3713 one. If you specify backslash as escape character in SQL, you
3714 must tell Emacs. Here's how to do that in your init file:
3716 \(add-hook 'sql-mode-hook
3718 (modify-syntax-entry ?\\\\ \".\" sql-mode-syntax-table)))"
3719 :abbrev-table sql-mode-abbrev-table
3721 (easy-menu-add sql-mode-menu
)); XEmacs
3723 (set (make-local-variable 'comment-start
) "--")
3724 ;; Make each buffer in sql-mode remember the "current" SQLi buffer.
3725 (make-local-variable 'sql-buffer
)
3726 ;; Add imenu support for sql-mode. Note that imenu-generic-expression
3727 ;; is buffer-local, so we don't need a local-variable for it. SQL is
3728 ;; case-insensitive, that's why we have to set imenu-case-fold-search.
3729 (setq imenu-generic-expression sql-imenu-generic-expression
3730 imenu-case-fold-search t
)
3731 ;; Make `sql-send-paragraph' work on paragraphs that contain indented
3733 (set (make-local-variable 'paragraph-separate
) "[\f]*$")
3734 (set (make-local-variable 'paragraph-start
) "[\n\f]")
3736 (setq abbrev-all-caps
1)
3737 ;; Contains the name of database objects
3738 (set (make-local-variable 'sql-contains-names
) t
)
3739 ;; Catch changes to sql-product and highlight accordingly
3740 (add-hook 'hack-local-variables-hook
'sql-highlight-product t t
))
3744 ;;; SQL interactive mode
3746 (put 'sql-interactive-mode
'mode-class
'special
)
3748 (defun sql-interactive-mode ()
3749 "Major mode to use a SQL interpreter interactively.
3751 Do not call this function by yourself. The environment must be
3752 initialized by an entry function specific for the SQL interpreter.
3753 See `sql-help' for a list of available entry functions.
3755 \\[comint-send-input] after the end of the process' output sends the
3756 text from the end of process to the end of the current line.
3757 \\[comint-send-input] before end of process output copies the current
3758 line minus the prompt to the end of the buffer and sends it.
3759 \\[comint-copy-old-input] just copies the current line.
3760 Use \\[sql-accumulate-and-indent] to enter multi-line statements.
3762 If you want to make multiple SQL buffers, rename the `*SQL*' buffer
3763 using \\[rename-buffer] or \\[rename-uniquely] and start a new process.
3764 See `sql-help' for a list of available entry functions. The last buffer
3765 created by such an entry function is the current SQLi buffer. SQL
3766 buffers will send strings to the SQLi buffer current at the time of
3767 their creation. See `sql-mode' for details.
3769 Sample session using two connections:
3771 1. Create first SQLi buffer by calling an entry function.
3772 2. Rename buffer \"*SQL*\" to \"*Connection 1*\".
3773 3. Create a SQL buffer \"test1.sql\".
3774 4. Create second SQLi buffer by calling an entry function.
3775 5. Rename buffer \"*SQL*\" to \"*Connection 2*\".
3776 6. Create a SQL buffer \"test2.sql\".
3778 Now \\[sql-send-region] in buffer \"test1.sql\" will send the region to
3779 buffer \"*Connection 1*\", \\[sql-send-region] in buffer \"test2.sql\"
3780 will send the region to buffer \"*Connection 2*\".
3782 If you accidentally suspend your process, use \\[comint-continue-subjob]
3783 to continue it. On some operating systems, this will not work because
3784 the signals are not supported.
3786 \\{sql-interactive-mode-map}
3787 Customization: Entry to this mode runs the hooks on `comint-mode-hook'
3788 and `sql-interactive-mode-hook' (in that order). Before each input, the
3789 hooks on `comint-input-filter-functions' are run. After each SQL
3790 interpreter output, the hooks on `comint-output-filter-functions' are
3793 Variable `sql-input-ring-file-name' controls the initialization of the
3796 Variables `comint-output-filter-functions', a hook, and
3797 `comint-scroll-to-bottom-on-input' and
3798 `comint-scroll-to-bottom-on-output' control whether input and output
3799 cause the window to scroll to the end of the buffer.
3801 If you want to make SQL buffers limited in length, add the function
3802 `comint-truncate-buffer' to `comint-output-filter-functions'.
3804 Here is an example for your init file. It keeps the SQLi buffer a
3807 \(add-hook 'sql-interactive-mode-hook
3808 \(function (lambda ()
3809 \(setq comint-output-filter-functions 'comint-truncate-buffer))))
3811 Here is another example. It will always put point back to the statement
3812 you entered, right above the output it created.
3814 \(setq comint-output-filter-functions
3815 \(function (lambda (STR) (comint-show-output))))"
3816 (delay-mode-hooks (comint-mode))
3818 ;; Get the `sql-product' for this interactive session.
3819 (set (make-local-variable 'sql-product
)
3820 (or sql-interactive-product
3824 (setq major-mode
'sql-interactive-mode
)
3826 (concat "SQLi[" (or (sql-get-product-feature sql-product
:name
)
3827 (symbol-name sql-product
)) "]"))
3828 (use-local-map sql-interactive-mode-map
)
3829 (if sql-interactive-mode-menu
3830 (easy-menu-add sql-interactive-mode-menu
)) ; XEmacs
3831 (set-syntax-table sql-mode-syntax-table
)
3833 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
3834 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
3835 ;; will have just one quote. Therefore syntactic highlighting is
3836 ;; disabled for interactive buffers. No imenu support.
3837 (sql-product-font-lock t nil
)
3839 ;; Enable commenting and uncommenting of the region.
3840 (set (make-local-variable 'comment-start
) "--")
3841 ;; Abbreviation table init and case-insensitive. It is not activated
3843 (setq local-abbrev-table sql-mode-abbrev-table
)
3844 (setq abbrev-all-caps
1)
3845 ;; Exiting the process will call sql-stop.
3846 (set-process-sentinel (get-buffer-process (current-buffer)) 'sql-stop
)
3847 ;; Save the connection and login params
3848 (set (make-local-variable 'sql-user
) sql-user
)
3849 (set (make-local-variable 'sql-database
) sql-database
)
3850 (set (make-local-variable 'sql-server
) sql-server
)
3851 (set (make-local-variable 'sql-port
) sql-port
)
3852 (set (make-local-variable 'sql-connection
) sql-connection
)
3853 (setq-default sql-connection nil
)
3854 ;; Contains the name of database objects
3855 (set (make-local-variable 'sql-contains-names
) t
)
3856 ;; Keep track of existing object names
3857 (set (make-local-variable 'sql-completion-object
) nil
)
3858 (set (make-local-variable 'sql-completion-column
) nil
)
3859 ;; Create a useful name for renaming this buffer later.
3860 (set (make-local-variable 'sql-alternate-buffer-name
)
3861 (sql-make-alternate-buffer-name))
3862 ;; User stuff. Initialize before the hook.
3863 (set (make-local-variable 'sql-prompt-regexp
)
3864 (sql-get-product-feature sql-product
:prompt-regexp
))
3865 (set (make-local-variable 'sql-prompt-length
)
3866 (sql-get-product-feature sql-product
:prompt-length
))
3867 (set (make-local-variable 'sql-prompt-cont-regexp
)
3868 (sql-get-product-feature sql-product
:prompt-cont-regexp
))
3869 (make-local-variable 'sql-output-newline-count
)
3870 (make-local-variable 'sql-preoutput-hold
)
3871 (make-local-variable 'sql-output-by-send
)
3872 (add-hook 'comint-preoutput-filter-functions
3873 'sql-interactive-remove-continuation-prompt nil t
)
3874 (make-local-variable 'sql-input-ring-separator
)
3875 (make-local-variable 'sql-input-ring-file-name
)
3876 ;; Run the mode hook (along with comint's hooks).
3877 (run-mode-hooks 'sql-interactive-mode-hook
)
3878 ;; Set comint based on user overrides.
3879 (setq comint-prompt-regexp
3880 (if sql-prompt-cont-regexp
3881 (concat "\\(" sql-prompt-regexp
3882 "\\|" sql-prompt-cont-regexp
"\\)")
3884 (setq left-margin sql-prompt-length
)
3885 ;; Install input sender
3886 (set (make-local-variable 'comint-input-sender
) 'sql-input-sender
)
3887 ;; People wanting a different history file for each
3888 ;; buffer/process/client/whatever can change separator and file-name
3889 ;; on the sql-interactive-mode-hook.
3890 (setq comint-input-ring-separator sql-input-ring-separator
3891 comint-input-ring-file-name sql-input-ring-file-name
)
3892 ;; Calling the hook before calling comint-read-input-ring allows users
3893 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook.
3894 (comint-read-input-ring t
))
3896 (defun sql-stop (process event
)
3897 "Called when the SQL process is stopped.
3899 Writes the input history to a history file using
3900 `comint-write-input-ring' and inserts a short message in the SQL buffer.
3902 This function is a sentinel watching the SQL interpreter process.
3903 Sentinels will always get the two parameters PROCESS and EVENT."
3904 (comint-write-input-ring)
3905 (if (and (eq (current-buffer) sql-buffer
)
3906 (not buffer-read-only
))
3907 (insert (format "\nProcess %s %s\n" process event
))
3908 (message "Process %s %s" process event
)))
3912 ;;; Connection handling
3914 (defun sql-read-connection (prompt &optional initial default
)
3915 "Read a connection name."
3916 (let ((completion-ignore-case t
))
3917 (completing-read prompt
3918 (mapcar (lambda (c) (car c
))
3919 sql-connection-alist
)
3920 nil t initial
'sql-connection-history default
)))
3923 (defun sql-connect (connection &optional new-name
)
3924 "Connect to an interactive session using CONNECTION settings.
3926 See `sql-connection-alist' to see how to define connections and
3929 The user will not be prompted for any login parameters if a value
3930 is specified in the connection settings."
3932 ;; Prompt for the connection from those defined in the alist
3934 (if sql-connection-alist
3935 (list (sql-read-connection "Connection: " nil
'(nil))
3939 ;; Are there connections defined
3940 (if sql-connection-alist
3943 ;; Get connection settings
3944 (let ((connect-set (assoc connection sql-connection-alist
)))
3945 ;; Settings are defined
3947 ;; Set the desired parameters
3948 (let (param-var login-params set-params rem-params
)
3950 ;; :sqli-login params variable
3952 (sql-get-product-feature sql-product
:sqli-login nil t
))
3954 ;; :sqli-login params value
3956 (sql-get-product-feature sql-product
:sqli-login
))
3958 ;; Params in the connection
3963 ((eq (car v
) 'sql-user
) 'user
)
3964 ((eq (car v
) 'sql-password
) 'password
)
3965 ((eq (car v
) 'sql-server
) 'server
)
3966 ((eq (car v
) 'sql-database
) 'database
)
3967 ((eq (car v
) 'sql-port
) 'port
)
3971 ;; the remaining params (w/o the connection params)
3973 (sql-for-each-login login-params
3974 (lambda (token plist
)
3975 (unless (member token set-params
)
3976 (if plist
(cons token plist
) token
)))))
3978 ;; Set the parameters and start the interactive session
3981 (set-default (car vv
) (eval (cadr vv
))))
3983 (setq-default sql-connection connection
)
3985 ;; Start the SQLi session with revised list of login parameters
3986 (eval `(let ((,param-var
',rem-params
))
3987 (sql-product-interactive sql-product new-name
))))
3989 (message "SQL Connection <%s> does not exist" connection
)
3992 (message "No SQL Connections defined")
3995 (defun sql-save-connection (name)
3996 "Captures the connection information of the current SQLi session.
3998 The information is appended to `sql-connection-alist' and
3999 optionally is saved to the user's init file."
4001 (interactive "sNew connection name: ")
4003 (unless (derived-mode-p 'sql-interactive-mode
)
4004 (error "Not in a SQL interactive mode!"))
4006 ;; Capture the buffer local settings
4007 (let* ((buf (current-buffer))
4008 (connection (buffer-local-value 'sql-connection buf
))
4009 (product (buffer-local-value 'sql-product buf
))
4010 (user (buffer-local-value 'sql-user buf
))
4011 (database (buffer-local-value 'sql-database buf
))
4012 (server (buffer-local-value 'sql-server buf
))
4013 (port (buffer-local-value 'sql-port buf
)))
4016 (message "This session was started by a connection; it's already been saved.")
4018 (let ((login (sql-get-product-feature product
:sqli-login
))
4019 (alist sql-connection-alist
)
4022 ;; Remove the existing connection if the user says so
4023 (when (and (assoc name alist
)
4024 (yes-or-no-p (format "Replace connection definition <%s>? " name
)))
4025 (setq alist
(assq-delete-all name alist
)))
4027 ;; Add the new connection if it doesn't exist
4028 (if (assoc name alist
)
4029 (message "Connection <%s> already exists" name
)
4034 (lambda (token _plist
)
4036 ((eq token
'product
) `(sql-product ',product
))
4037 ((eq token
'user
) `(sql-user ,user
))
4038 ((eq token
'database
) `(sql-database ,database
))
4039 ((eq token
'server
) `(sql-server ,server
))
4040 ((eq token
'port
) `(sql-port ,port
)))))))
4042 (setq alist
(append alist
(list connect
)))
4044 ;; confirm whether we want to save the connections
4045 (if (yes-or-no-p "Save the connections for future sessions? ")
4046 (customize-save-variable 'sql-connection-alist alist
)
4047 (customize-set-variable 'sql-connection-alist alist
)))))))
4049 (defun sql-connection-menu-filter (tail)
4050 "Generates menu entries for using each connection."
4055 (format "Connection <%s>\t%s" (car conn
)
4056 (let ((sql-user "") (sql-database "")
4057 (sql-server "") (sql-port 0))
4058 (eval `(let ,(cdr conn
) (sql-make-alternate-buffer-name)))))
4059 (list 'sql-connect
(car conn
))
4061 sql-connection-alist
)
4066 ;;; Entry functions for different SQL interpreters.
4069 (defun sql-product-interactive (&optional product new-name
)
4070 "Run PRODUCT interpreter as an inferior process.
4072 If buffer `*SQL*' exists but no process is running, make a new process.
4073 If buffer exists and a process is running, just switch to buffer `*SQL*'.
4075 To specify the SQL product, prefix the call with
4076 \\[universal-argument]. To set the buffer name as well, prefix
4077 the call to \\[sql-product-interactive] with
4078 \\[universal-argument] \\[universal-argument].
4080 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4083 ;; Handle universal arguments if specified
4084 (when (not (or executing-kbd-macro noninteractive
))
4085 (when (and (consp product
)
4087 (numberp (car product
)))
4088 (when (>= (prefix-numeric-value product
) 16)
4089 (when (not new-name
)
4090 (setq new-name
'(4)))
4091 (setq product
'(4)))))
4093 ;; Get the value of product that we need
4096 ((= (prefix-numeric-value product
) 4) ; C-u, prompt for product
4097 (sql-read-product "SQL product: " sql-product
))
4098 ((and product
; Product specified
4099 (symbolp product
)) product
)
4100 (t sql-product
))) ; Default to sql-product
4102 ;; If we have a product and it has a interactive mode
4104 (when (sql-get-product-feature product
:sqli-comint-func
)
4105 ;; If no new name specified, try to pop to an active SQL
4106 ;; interactive for the same product
4107 (let ((buf (sql-find-sqli-buffer product sql-connection
)))
4108 (if (and (not new-name
) buf
)
4111 ;; We have a new name or sql-buffer doesn't exist or match
4112 ;; Start by remembering where we start
4113 (let ((start-buffer (current-buffer))
4117 (apply 'sql-get-login
(sql-get-product-feature product
:sqli-login
))
4119 ;; Connect to database.
4120 (message "Login...")
4121 (let ((sql-user (default-value 'sql-user
))
4122 (sql-password (default-value 'sql-password
))
4123 (sql-server (default-value 'sql-server
))
4124 (sql-database (default-value 'sql-database
))
4125 (sql-port (default-value 'sql-port
)))
4126 (funcall (sql-get-product-feature product
:sqli-comint-func
)
4128 (sql-get-product-feature product
:sqli-options
)))
4131 (let ((sql-interactive-product product
))
4132 (sql-interactive-mode))
4134 ;; Set the new buffer name
4135 (setq new-sqli-buffer
(current-buffer))
4137 (sql-rename-buffer new-name
))
4138 (set (make-local-variable 'sql-buffer
)
4139 (buffer-name new-sqli-buffer
))
4141 ;; Set `sql-buffer' in the start buffer
4142 (with-current-buffer start-buffer
4143 (when (derived-mode-p 'sql-mode
)
4144 (setq sql-buffer
(buffer-name new-sqli-buffer
))
4145 (run-hooks 'sql-set-sqli-hook
)))
4148 (message "Login...done")
4149 (run-hooks 'sql-login-hook
)
4150 (pop-to-buffer new-sqli-buffer
)))))
4151 (message "No default SQL product defined. Set `sql-product'.")))
4153 (defun sql-comint (product params
)
4154 "Set up a comint buffer to run the SQL processor.
4156 PRODUCT is the SQL product. PARAMS is a list of strings which are
4157 passed as command line arguments."
4158 (let ((program (sql-get-product-feature product
:sqli-program
))
4160 ;; Make sure we can find the program. `executable-find' does not
4161 ;; work for remote hosts; we suppress the check there.
4162 (unless (or (file-remote-p default-directory
)
4163 (executable-find program
))
4164 (error "Unable to locate SQL program \'%s\'" program
))
4165 ;; Make sure buffer name is unique.
4166 (when (sql-buffer-live-p (format "*%s*" buf-name
))
4167 (setq buf-name
(format "SQL-%s" product
))
4168 (when (sql-buffer-live-p (format "*%s*" buf-name
))
4170 (while (sql-buffer-live-p
4172 (setq buf-name
(format "SQL-%s%d" product i
))))
4175 (apply 'make-comint buf-name program nil params
))))
4178 (defun sql-oracle (&optional buffer
)
4179 "Run sqlplus by Oracle as an inferior process.
4181 If buffer `*SQL*' exists but no process is running, make a new process.
4182 If buffer exists and a process is running, just switch to buffer
4185 Interpreter used comes from variable `sql-oracle-program'. Login uses
4186 the variables `sql-user', `sql-password', and `sql-database' as
4187 defaults, if set. Additional command line parameters can be stored in
4188 the list `sql-oracle-options'.
4190 The buffer is put in SQL interactive mode, giving commands for sending
4191 input. See `sql-interactive-mode'.
4193 To set the buffer name directly, use \\[universal-argument]
4194 before \\[sql-oracle]. Once session has started,
4195 \\[sql-rename-buffer] can be called separately to rename the
4198 To specify a coding system for converting non-ASCII characters
4199 in the input and output to the process, use \\[universal-coding-system-argument]
4200 before \\[sql-oracle]. You can also specify this with \\[set-buffer-process-coding-system]
4201 in the SQL buffer, after you start the process.
4202 The default comes from `process-coding-system-alist' and
4203 `default-process-coding-system'.
4205 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4207 (sql-product-interactive 'oracle buffer
))
4209 (defun sql-comint-oracle (product options
)
4210 "Create comint buffer and connect to Oracle."
4211 ;; Produce user/password@database construct. Password without user
4212 ;; is meaningless; database without user/password is meaningless,
4213 ;; because "@param" will ask sqlplus to interpret the script
4215 (let ((parameter nil
))
4216 (if (not (string= "" sql-user
))
4217 (if (not (string= "" sql-password
))
4218 (setq parameter
(concat sql-user
"/" sql-password
))
4219 (setq parameter sql-user
)))
4220 (if (and parameter
(not (string= "" sql-database
)))
4221 (setq parameter
(concat parameter
"@" sql-database
)))
4223 (setq parameter
(nconc (list parameter
) options
))
4224 (setq parameter options
))
4225 (sql-comint product parameter
)))
4227 (defun sql-oracle-save-settings (sqlbuf)
4228 "Saves most SQL*Plus settings so they may be reset by \\[sql-redirect]."
4229 ;; Note: does not capture the following settings:
4239 ;; SQLPLUSCOMPATIBILITY
4245 ;; (apply 'concat (append
4251 (concat "SHOW ARRAYSIZE AUTOCOMMIT AUTOPRINT AUTORECOVERY AUTOTRACE"
4252 " CMDSEP COLSEP COPYCOMMIT DESCRIBE ECHO EDITFILE EMBEDDED"
4253 " ESCAPE FLAGGER FLUSH HEADING INSTANCE LINESIZE LNO LOBOFFSET"
4254 " LOGSOURCE LONG LONGCHUNKSIZE NEWPAGE NULL NUMFORMAT NUMWIDTH"
4255 " PAGESIZE PAUSE PNO RECSEP SERVEROUTPUT SHIFTINOUT SHOWMODE"
4256 " SPOOL SQLBLANKLINES SQLCASE SQLCODE SQLCONTINUE SQLNUMBER"
4257 " SQLPROMPT SUFFIX TAB TERMOUT TIMING TRIMOUT TRIMSPOOL VERIFY")
4261 ;; option "c" (hex xx)
4264 (concat "SHOW BLOCKTERMINATOR CONCAT DEFINE SQLPREFIX SQLTERMINATOR"
4265 " UNDERLINE HEADSEP RECSEPCHAR")
4266 "^\\(.+\\) (hex ..)$"
4269 ;; FEEDBACK ON for 99 or more rows
4274 "^\\(?:FEEDBACK ON for \\([[:digit:]]+\\) or more rows\\|feedback \\(OFF\\)\\)"
4275 "SET FEEDBACK \\1\\2")
4277 ;; wrap : lines will be wrapped
4278 ;; wrap : lines will be truncated
4279 (list (concat "SET WRAP "
4281 (car (sql-redirect-value
4284 "^wrap : lines will be \\(wrapped\\|truncated\\)" 1))
4288 (defun sql-oracle-restore-settings (sqlbuf saved-settings
)
4289 "Restore the SQL*Plus settings in SAVED-SETTINGS."
4291 ;; Remove any settings that haven't changed
4293 (lambda (one-cur-setting)
4294 (setq saved-settings
(delete one-cur-setting saved-settings
)))
4295 (sql-oracle-save-settings sqlbuf
))
4297 ;; Restore the changed settings
4298 (sql-redirect sqlbuf saved-settings
))
4300 (defun sql-oracle-list-all (sqlbuf outbuf enhanced table-name
)
4301 ;; Query from USER_OBJECTS or ALL_OBJECTS
4302 (let ((settings (sql-oracle-save-settings sqlbuf
))
4305 "SELECT INITCAP(x.object_type) AS SQL_EL_TYPE "
4306 ", x.object_name AS SQL_EL_NAME "
4307 "FROM user_objects x "
4308 "WHERE x.object_type NOT LIKE '%% BODY' "
4312 "SELECT INITCAP(x.object_type) AS SQL_EL_TYPE "
4313 ", x.owner ||'.'|| x.object_name AS SQL_EL_NAME "
4314 "FROM all_objects x "
4315 "WHERE x.object_type NOT LIKE '%% BODY' "
4316 "AND x.owner <> 'SYS' "
4319 (sql-redirect sqlbuf
4320 (concat "SET LINESIZE 80 PAGESIZE 50000 TRIMOUT ON"
4321 " TAB OFF TIMING OFF FEEDBACK OFF"))
4323 (sql-redirect sqlbuf
4324 (list "COLUMN SQL_EL_TYPE HEADING \"Type\" FORMAT A19"
4325 "COLUMN SQL_EL_NAME HEADING \"Name\""
4326 (format "COLUMN SQL_EL_NAME FORMAT A%d"
4327 (if enhanced
60 35))))
4329 (sql-redirect sqlbuf
4330 (if enhanced enhanced-sql simple-sql
)
4333 (sql-redirect sqlbuf
4334 '("COLUMN SQL_EL_NAME CLEAR"
4335 "COLUMN SQL_EL_TYPE CLEAR"))
4337 (sql-oracle-restore-settings sqlbuf settings
)))
4339 (defun sql-oracle-list-table (sqlbuf outbuf enhanced table-name
)
4340 "Implements :list-table under Oracle."
4341 (let ((settings (sql-oracle-save-settings sqlbuf
)))
4343 (sql-redirect sqlbuf
4345 (concat "SET LINESIZE %d PAGESIZE 50000"
4346 " DESCRIBE DEPTH 1 LINENUM OFF INDENT ON")
4347 (max 65 (min 120 (window-width)))))
4349 (sql-redirect sqlbuf
(format "DESCRIBE %s" table-name
)
4352 (sql-oracle-restore-settings sqlbuf settings
)))
4354 (defcustom sql-oracle-completion-types
'("FUNCTION" "PACKAGE" "PROCEDURE"
4355 "SEQUENCE" "SYNONYM" "TABLE" "TRIGGER"
4357 "List of object types to include for completion under Oracle.
4359 See the distinct values in ALL_OBJECTS.OBJECT_TYPE for possible values."
4361 :type
'(repeat string
)
4364 (defun sql-oracle-completion-object (sqlbuf schema
)
4370 (format "owner||'.'||object_name AS o FROM all_objects WHERE owner = %s AND "
4371 (sql-str-literal (upcase schema
)))
4372 "object_name AS o FROM user_objects WHERE ")
4373 "temporary = 'N' AND generated = 'N' AND secondary = 'N' AND "
4375 (mapconcat (function sql-str-literal
) sql-oracle-completion-types
",")
4377 "^[\001]\\(.+\\)$" 1))
4381 (defun sql-sybase (&optional buffer
)
4382 "Run isql by Sybase as an inferior process.
4384 If buffer `*SQL*' exists but no process is running, make a new process.
4385 If buffer exists and a process is running, just switch to buffer
4388 Interpreter used comes from variable `sql-sybase-program'. Login uses
4389 the variables `sql-server', `sql-user', `sql-password', and
4390 `sql-database' as defaults, if set. Additional command line parameters
4391 can be stored in the list `sql-sybase-options'.
4393 The buffer is put in SQL interactive mode, giving commands for sending
4394 input. See `sql-interactive-mode'.
4396 To set the buffer name directly, use \\[universal-argument]
4397 before \\[sql-sybase]. Once session has started,
4398 \\[sql-rename-buffer] can be called separately to rename the
4401 To specify a coding system for converting non-ASCII characters
4402 in the input and output to the process, use \\[universal-coding-system-argument]
4403 before \\[sql-sybase]. You can also specify this with \\[set-buffer-process-coding-system]
4404 in the SQL buffer, after you start the process.
4405 The default comes from `process-coding-system-alist' and
4406 `default-process-coding-system'.
4408 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4410 (sql-product-interactive 'sybase buffer
))
4412 (defun sql-comint-sybase (product options
)
4413 "Create comint buffer and connect to Sybase."
4414 ;; Put all parameters to the program (if defined) in a list and call
4416 (let ((params options
))
4417 (if (not (string= "" sql-server
))
4418 (setq params
(append (list "-S" sql-server
) params
)))
4419 (if (not (string= "" sql-database
))
4420 (setq params
(append (list "-D" sql-database
) params
)))
4421 (if (not (string= "" sql-password
))
4422 (setq params
(append (list "-P" sql-password
) params
)))
4423 (if (not (string= "" sql-user
))
4424 (setq params
(append (list "-U" sql-user
) params
)))
4425 (sql-comint product params
)))
4430 (defun sql-informix (&optional buffer
)
4431 "Run dbaccess by Informix as an inferior process.
4433 If buffer `*SQL*' exists but no process is running, make a new process.
4434 If buffer exists and a process is running, just switch to buffer
4437 Interpreter used comes from variable `sql-informix-program'. Login uses
4438 the variable `sql-database' as default, if set.
4440 The buffer is put in SQL interactive mode, giving commands for sending
4441 input. See `sql-interactive-mode'.
4443 To set the buffer name directly, use \\[universal-argument]
4444 before \\[sql-informix]. Once session has started,
4445 \\[sql-rename-buffer] can be called separately to rename the
4448 To specify a coding system for converting non-ASCII characters
4449 in the input and output to the process, use \\[universal-coding-system-argument]
4450 before \\[sql-informix]. You can also specify this with \\[set-buffer-process-coding-system]
4451 in the SQL buffer, after you start the process.
4452 The default comes from `process-coding-system-alist' and
4453 `default-process-coding-system'.
4455 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4457 (sql-product-interactive 'informix buffer
))
4459 (defun sql-comint-informix (product options
)
4460 "Create comint buffer and connect to Informix."
4461 ;; username and password are ignored.
4462 (let ((db (if (string= "" sql-database
)
4464 (if (string= "" sql-server
)
4466 (concat sql-database
"@" sql-server
)))))
4467 (sql-comint product
(append `(,db
"-") options
))))
4472 (defun sql-sqlite (&optional buffer
)
4473 "Run sqlite as an inferior process.
4475 SQLite is free software.
4477 If buffer `*SQL*' exists but no process is running, make a new process.
4478 If buffer exists and a process is running, just switch to buffer
4481 Interpreter used comes from variable `sql-sqlite-program'. Login uses
4482 the variables `sql-user', `sql-password', `sql-database', and
4483 `sql-server' as defaults, if set. Additional command line parameters
4484 can be stored in the list `sql-sqlite-options'.
4486 The buffer is put in SQL interactive mode, giving commands for sending
4487 input. See `sql-interactive-mode'.
4489 To set the buffer name directly, use \\[universal-argument]
4490 before \\[sql-sqlite]. Once session has started,
4491 \\[sql-rename-buffer] can be called separately to rename the
4494 To specify a coding system for converting non-ASCII characters
4495 in the input and output to the process, use \\[universal-coding-system-argument]
4496 before \\[sql-sqlite]. You can also specify this with \\[set-buffer-process-coding-system]
4497 in the SQL buffer, after you start the process.
4498 The default comes from `process-coding-system-alist' and
4499 `default-process-coding-system'.
4501 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4503 (sql-product-interactive 'sqlite buffer
))
4505 (defun sql-comint-sqlite (product options
)
4506 "Create comint buffer and connect to SQLite."
4507 ;; Put all parameters to the program (if defined) in a list and call
4510 (if (not (string= "" sql-database
))
4511 (setq params
(append (list (expand-file-name sql-database
))
4513 (setq params
(append options params
))
4514 (sql-comint product params
)))
4516 (defun sql-sqlite-completion-object (sqlbuf schema
)
4517 (sql-redirect-value sqlbuf
".tables" "\\sw\\(?:\\sw\\|\\s_\\)*" 0))
4522 (defun sql-mysql (&optional buffer
)
4523 "Run mysql by TcX as an inferior process.
4525 Mysql versions 3.23 and up are free software.
4527 If buffer `*SQL*' exists but no process is running, make a new process.
4528 If buffer exists and a process is running, just switch to buffer
4531 Interpreter used comes from variable `sql-mysql-program'. Login uses
4532 the variables `sql-user', `sql-password', `sql-database', and
4533 `sql-server' as defaults, if set. Additional command line parameters
4534 can be stored in the list `sql-mysql-options'.
4536 The buffer is put in SQL interactive mode, giving commands for sending
4537 input. See `sql-interactive-mode'.
4539 To set the buffer name directly, use \\[universal-argument]
4540 before \\[sql-mysql]. Once session has started,
4541 \\[sql-rename-buffer] can be called separately to rename the
4544 To specify a coding system for converting non-ASCII characters
4545 in the input and output to the process, use \\[universal-coding-system-argument]
4546 before \\[sql-mysql]. You can also specify this with \\[set-buffer-process-coding-system]
4547 in the SQL buffer, after you start the process.
4548 The default comes from `process-coding-system-alist' and
4549 `default-process-coding-system'.
4551 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4553 (sql-product-interactive 'mysql buffer
))
4555 (defun sql-comint-mysql (product options
)
4556 "Create comint buffer and connect to MySQL."
4557 ;; Put all parameters to the program (if defined) in a list and call
4560 (if (not (string= "" sql-database
))
4561 (setq params
(append (list sql-database
) params
)))
4562 (if (not (string= "" sql-server
))
4563 (setq params
(append (list (concat "--host=" sql-server
)) params
)))
4564 (if (not (= 0 sql-port
))
4565 (setq params
(append (list (concat "--port=" (number-to-string sql-port
))) params
)))
4566 (if (not (string= "" sql-password
))
4567 (setq params
(append (list (concat "--password=" sql-password
)) params
)))
4568 (if (not (string= "" sql-user
))
4569 (setq params
(append (list (concat "--user=" sql-user
)) params
)))
4570 (setq params
(append options params
))
4571 (sql-comint product params
)))
4576 (defun sql-solid (&optional buffer
)
4577 "Run solsql by Solid as an inferior process.
4579 If buffer `*SQL*' exists but no process is running, make a new process.
4580 If buffer exists and a process is running, just switch to buffer
4583 Interpreter used comes from variable `sql-solid-program'. Login uses
4584 the variables `sql-user', `sql-password', and `sql-server' as
4587 The buffer is put in SQL interactive mode, giving commands for sending
4588 input. See `sql-interactive-mode'.
4590 To set the buffer name directly, use \\[universal-argument]
4591 before \\[sql-solid]. Once session has started,
4592 \\[sql-rename-buffer] can be called separately to rename the
4595 To specify a coding system for converting non-ASCII characters
4596 in the input and output to the process, use \\[universal-coding-system-argument]
4597 before \\[sql-solid]. You can also specify this with \\[set-buffer-process-coding-system]
4598 in the SQL buffer, after you start the process.
4599 The default comes from `process-coding-system-alist' and
4600 `default-process-coding-system'.
4602 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4604 (sql-product-interactive 'solid buffer
))
4606 (defun sql-comint-solid (product options
)
4607 "Create comint buffer and connect to Solid."
4608 ;; Put all parameters to the program (if defined) in a list and call
4610 (let ((params options
))
4611 ;; It only makes sense if both username and password are there.
4612 (if (not (or (string= "" sql-user
)
4613 (string= "" sql-password
)))
4614 (setq params
(append (list sql-user sql-password
) params
)))
4615 (if (not (string= "" sql-server
))
4616 (setq params
(append (list sql-server
) params
)))
4617 (sql-comint product params
)))
4622 (defun sql-ingres (&optional buffer
)
4623 "Run sql by Ingres as an inferior process.
4625 If buffer `*SQL*' exists but no process is running, make a new process.
4626 If buffer exists and a process is running, just switch to buffer
4629 Interpreter used comes from variable `sql-ingres-program'. Login uses
4630 the variable `sql-database' as default, if set.
4632 The buffer is put in SQL interactive mode, giving commands for sending
4633 input. See `sql-interactive-mode'.
4635 To set the buffer name directly, use \\[universal-argument]
4636 before \\[sql-ingres]. Once session has started,
4637 \\[sql-rename-buffer] can be called separately to rename the
4640 To specify a coding system for converting non-ASCII characters
4641 in the input and output to the process, use \\[universal-coding-system-argument]
4642 before \\[sql-ingres]. You can also specify this with \\[set-buffer-process-coding-system]
4643 in the SQL buffer, after you start the process.
4644 The default comes from `process-coding-system-alist' and
4645 `default-process-coding-system'.
4647 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4649 (sql-product-interactive 'ingres buffer
))
4651 (defun sql-comint-ingres (product options
)
4652 "Create comint buffer and connect to Ingres."
4653 ;; username and password are ignored.
4655 (append (if (string= "" sql-database
)
4657 (list sql-database
))
4663 (defun sql-ms (&optional buffer
)
4664 "Run osql by Microsoft as an inferior process.
4666 If buffer `*SQL*' exists but no process is running, make a new process.
4667 If buffer exists and a process is running, just switch to buffer
4670 Interpreter used comes from variable `sql-ms-program'. Login uses the
4671 variables `sql-user', `sql-password', `sql-database', and `sql-server'
4672 as defaults, if set. Additional command line parameters can be stored
4673 in the list `sql-ms-options'.
4675 The buffer is put in SQL interactive mode, giving commands for sending
4676 input. See `sql-interactive-mode'.
4678 To set the buffer name directly, use \\[universal-argument]
4679 before \\[sql-ms]. Once session has started,
4680 \\[sql-rename-buffer] can be called separately to rename the
4683 To specify a coding system for converting non-ASCII characters
4684 in the input and output to the process, use \\[universal-coding-system-argument]
4685 before \\[sql-ms]. You can also specify this with \\[set-buffer-process-coding-system]
4686 in the SQL buffer, after you start the process.
4687 The default comes from `process-coding-system-alist' and
4688 `default-process-coding-system'.
4690 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4692 (sql-product-interactive 'ms buffer
))
4694 (defun sql-comint-ms (product options
)
4695 "Create comint buffer and connect to Microsoft SQL Server."
4696 ;; Put all parameters to the program (if defined) in a list and call
4698 (let ((params options
))
4699 (if (not (string= "" sql-server
))
4700 (setq params
(append (list "-S" sql-server
) params
)))
4701 (if (not (string= "" sql-database
))
4702 (setq params
(append (list "-d" sql-database
) params
)))
4703 (if (not (string= "" sql-user
))
4704 (setq params
(append (list "-U" sql-user
) params
)))
4705 (if (not (string= "" sql-password
))
4706 (setq params
(append (list "-P" sql-password
) params
))
4707 (if (string= "" sql-user
)
4708 ;; if neither user nor password is provided, use system
4710 (setq params
(append (list "-E") params
))
4711 ;; If -P is passed to ISQL as the last argument without a
4712 ;; password, it's considered null.
4713 (setq params
(append params
(list "-P")))))
4714 (sql-comint product params
)))
4719 (defun sql-postgres (&optional buffer
)
4720 "Run psql by Postgres 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-postgres-program'. Login uses
4727 the variables `sql-database' and `sql-server' as default, if set.
4728 Additional command line parameters can be stored in the list
4729 `sql-postgres-options'.
4731 The buffer is put in SQL interactive mode, giving commands for sending
4732 input. See `sql-interactive-mode'.
4734 To set the buffer name directly, use \\[universal-argument]
4735 before \\[sql-postgres]. Once session has started,
4736 \\[sql-rename-buffer] can be called separately to rename the
4739 To specify a coding system for converting non-ASCII characters
4740 in the input and output to the process, use \\[universal-coding-system-argument]
4741 before \\[sql-postgres]. You can also specify this with \\[set-buffer-process-coding-system]
4742 in the SQL buffer, after you start the process.
4743 The default comes from `process-coding-system-alist' and
4744 `default-process-coding-system'. If your output lines end with ^M,
4745 your might try undecided-dos as a coding system. If this doesn't help,
4746 Try to set `comint-output-filter-functions' like this:
4748 \(setq comint-output-filter-functions (append comint-output-filter-functions
4749 '(comint-strip-ctrl-m)))
4751 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4753 (sql-product-interactive 'postgres buffer
))
4755 (defun sql-comint-postgres (product options
)
4756 "Create comint buffer and connect to Postgres."
4757 ;; username and password are ignored. Mark Stosberg suggest to add
4758 ;; the database at the end. Jason Beegan suggest using --pset and
4759 ;; pager=off instead of \\o|cat. The later was the solution by
4760 ;; Gregor Zych. Jason's suggestion is the default value for
4761 ;; sql-postgres-options.
4762 (let ((params options
))
4763 (if (not (string= "" sql-database
))
4764 (setq params
(append params
(list sql-database
))))
4765 (if (not (string= "" sql-server
))
4766 (setq params
(append (list "-h" sql-server
) params
)))
4767 (if (not (string= "" sql-user
))
4768 (setq params
(append (list "-U" sql-user
) params
)))
4769 (if (not (= 0 sql-port
))
4770 (setq params
(append (list "-p" (number-to-string sql-port
)) params
)))
4771 (sql-comint product params
)))
4773 (defun sql-postgres-completion-object (sqlbuf schema
)
4775 (sql-redirect sqlbuf
"\\t on")
4776 (setq a
(car (sql-redirect-value sqlbuf
"\\a" "Output format is \\(.*\\)[.]$" 1)))
4777 (when (string= a
"aligned")
4778 (sql-redirect sqlbuf
"\\a"))
4779 (setq fs
(or (car (sql-redirect-value sqlbuf
"\\f" "Field separator is \"\\(.\\)[.]$" 1)) "|"))
4781 (setq re
(concat "^\\([^" fs
"]*\\)" fs
"\\([^" fs
"]*\\)" fs
"[^" fs
"]*" fs
"[^" fs
"]*$"))
4782 (setq cl
(if (not schema
)
4783 (sql-redirect-value sqlbuf
"\\d" re
'(1 2))
4784 (append (sql-redirect-value sqlbuf
(format "\\dt %s.*" schema
) re
'(1 2))
4785 (sql-redirect-value sqlbuf
(format "\\dv %s.*" schema
) re
'(1 2))
4786 (sql-redirect-value sqlbuf
(format "\\ds %s.*" schema
) re
'(1 2)))))
4788 ;; Restore tuples and alignment to what they were
4789 (sql-redirect sqlbuf
"\\t off")
4790 (when (not (string= a
"aligned"))
4791 (sql-redirect sqlbuf
"\\a"))
4793 ;; Return the list of table names (public schema name can be omitted)
4794 (mapcar (lambda (tbl)
4795 (if (string= (car tbl
) "public")
4797 (format "%s.%s" (car tbl
) (cadr tbl
))))
4803 (defun sql-interbase (&optional buffer
)
4804 "Run isql by Interbase as an inferior process.
4806 If buffer `*SQL*' exists but no process is running, make a new process.
4807 If buffer exists and a process is running, just switch to buffer
4810 Interpreter used comes from variable `sql-interbase-program'. Login
4811 uses the variables `sql-user', `sql-password', and `sql-database' as
4814 The buffer is put in SQL interactive mode, giving commands for sending
4815 input. See `sql-interactive-mode'.
4817 To set the buffer name directly, use \\[universal-argument]
4818 before \\[sql-interbase]. Once session has started,
4819 \\[sql-rename-buffer] can be called separately to rename the
4822 To specify a coding system for converting non-ASCII characters
4823 in the input and output to the process, use \\[universal-coding-system-argument]
4824 before \\[sql-interbase]. You can also specify this with \\[set-buffer-process-coding-system]
4825 in the SQL buffer, after you start the process.
4826 The default comes from `process-coding-system-alist' and
4827 `default-process-coding-system'.
4829 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4831 (sql-product-interactive 'interbase buffer
))
4833 (defun sql-comint-interbase (product options
)
4834 "Create comint buffer and connect to Interbase."
4835 ;; Put all parameters to the program (if defined) in a list and call
4837 (let ((params options
))
4838 (if (not (string= "" sql-user
))
4839 (setq params
(append (list "-u" sql-user
) params
)))
4840 (if (not (string= "" sql-password
))
4841 (setq params
(append (list "-p" sql-password
) params
)))
4842 (if (not (string= "" sql-database
))
4843 (setq params
(cons sql-database params
))) ; add to the front!
4844 (sql-comint product params
)))
4849 (defun sql-db2 (&optional buffer
)
4850 "Run db2 by IBM as an inferior process.
4852 If buffer `*SQL*' exists but no process is running, make a new process.
4853 If buffer exists and a process is running, just switch to buffer
4856 Interpreter used comes from variable `sql-db2-program'. There is not
4859 The buffer is put in SQL interactive mode, giving commands for sending
4860 input. See `sql-interactive-mode'.
4862 If you use \\[sql-accumulate-and-indent] to send multiline commands to
4863 db2, newlines will be escaped if necessary. If you don't want that, set
4864 `comint-input-sender' back to `comint-simple-send' by writing an after
4865 advice. See the elisp manual for more information.
4867 To set the buffer name directly, use \\[universal-argument]
4868 before \\[sql-db2]. Once session has started,
4869 \\[sql-rename-buffer] can be called separately to rename the
4872 To specify a coding system for converting non-ASCII characters
4873 in the input and output to the process, use \\[universal-coding-system-argument]
4874 before \\[sql-db2]. You can also specify this with \\[set-buffer-process-coding-system]
4875 in the SQL buffer, after you start the process.
4876 The default comes from `process-coding-system-alist' and
4877 `default-process-coding-system'.
4879 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4881 (sql-product-interactive 'db2 buffer
))
4883 (defun sql-comint-db2 (product options
)
4884 "Create comint buffer and connect to DB2."
4885 ;; Put all parameters to the program (if defined) in a list and call
4887 (sql-comint product options
))
4890 (defun sql-linter (&optional buffer
)
4891 "Run inl by RELEX as an inferior process.
4893 If buffer `*SQL*' exists but no process is running, make a new process.
4894 If buffer exists and a process is running, just switch to buffer
4897 Interpreter used comes from variable `sql-linter-program' - usually `inl'.
4898 Login uses the variables `sql-user', `sql-password', `sql-database' and
4899 `sql-server' as defaults, if set. Additional command line parameters
4900 can be stored in the list `sql-linter-options'. Run inl -h to get help on
4903 `sql-database' is used to set the LINTER_MBX environment variable for
4904 local connections, `sql-server' refers to the server name from the
4905 `nodetab' file for the network connection (dbc_tcp or friends must run
4906 for this to work). If `sql-password' is an empty string, inl will use
4909 The buffer is put in SQL interactive mode, giving commands for sending
4910 input. See `sql-interactive-mode'.
4912 To set the buffer name directly, use \\[universal-argument]
4913 before \\[sql-linter]. Once session has started,
4914 \\[sql-rename-buffer] can be called separately to rename the
4917 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
4919 (sql-product-interactive 'linter buffer
))
4921 (defun sql-comint-linter (product options
)
4922 "Create comint buffer and connect to Linter."
4923 ;; Put all parameters to the program (if defined) in a list and call
4925 (let ((params options
)
4927 (old-mbx (getenv "LINTER_MBX")))
4928 (if (not (string= "" sql-user
))
4929 (setq login
(concat sql-user
"/" sql-password
)))
4930 (setq params
(append (list "-u" login
) params
))
4931 (if (not (string= "" sql-server
))
4932 (setq params
(append (list "-n" sql-server
) params
)))
4933 (if (string= "" sql-database
)
4934 (setenv "LINTER_MBX" nil
)
4935 (setenv "LINTER_MBX" sql-database
))
4936 (sql-comint product params
)
4937 (setenv "LINTER_MBX" old-mbx
)))
4943 ;;; sql.el ends here
4945 ; LocalWords: sql SQL SQLite sqlite Sybase Informix MySQL
4946 ; LocalWords: Postgres SQLServer SQLi