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