* speedbar.el (speedbar-ignored-path-regexp, speedbar-line-path)
[emacs.git] / lisp / progmodes / sql.el
blob6d73abb1432716f5760dc33b47e509d88294fa8f
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>
8 ;; Version: 2.0.1
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)
18 ;; any later version.
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.
30 ;;; Commentary:
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
62 ;; use.
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/>.
81 ;;; Bugs:
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
87 ;; awkward.
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.
96 ;;; Product Support:
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
100 ;; below):
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.
108 ;; (xyz
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."
123 ;; :type 'file
124 ;; :group 'SQL)
126 ;; (defcustom sql-xyz-options '("-X" "-Y" "-Z")
127 ;; "*List of additional options for `sql-xyz-program'."
128 ;; :type '(repeat string)
129 ;; :group 'SQL)
131 ;; 4) Add an entry to SQL->Product submenu.
133 ;; ["XyzDB" sql-highlight-xyz-keywords
134 ;; :style radio
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."
148 ;; (interactive)
149 ;; (sql-set-product 'xyz))
151 ;; 7) Add an autoloaded SQLi function.
153 ;; ;;;###autoload
154 ;; (defun sql-xyz ()
155 ;; "Run ixyz by XyzDB as an inferior process."
156 ;; (interactive)
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
180 ;; nil params))))
182 ;; 9) Save and compile sql.el.
184 ;;; To Do:
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
212 ;;; Code:
214 (require 'comint)
215 ;; Need the following to allow GNU Emacs 19 to compile the file.
216 (eval-when-compile
217 (require 'regexp-opt))
218 (require 'custom)
219 (eval-when-compile ;; needed in Emacs 19, 20
220 (setq max-specpdl-size 2000))
222 (defvar font-lock-keyword-face)
223 (defvar font-lock-set-defaults)
224 (defvar font-lock-string-face)
226 ;;; Allow customization
228 (defgroup SQL nil
229 "Running a SQL interpreter from within Emacs buffers."
230 :version "20.4"
231 :group 'processes)
233 ;; These four variables will be used as defaults, if set.
235 (defcustom sql-user ""
236 "*Default username."
237 :type 'string
238 :group 'SQL)
240 (defcustom sql-password ""
241 "*Default password.
243 Storing your password in a textfile such as ~/.emacs could be dangerous.
244 Customizing your password will store it in your ~/.emacs file."
245 :type 'string
246 :group 'SQL)
248 (defcustom sql-database ""
249 "*Default database."
250 :type 'string
251 :group 'SQL)
253 (defcustom sql-server ""
254 "*Default server or host."
255 :type 'string
256 :group 'SQL)
258 ;; SQL Product support
259 (defcustom sql-product 'ansi
260 "*Select the SQL database product used so that buffers can be
261 highlighted properly when you open them."
262 :type '(choice (const :tag "ANSI" ansi)
263 (const :tag "DB2" db2)
264 (const :tag "Informix" informix)
265 (const :tag "Ingres" ingres)
266 (const :tag "Interbase" interbase)
267 (const :tag "Linter" linter)
268 (const :tag "Microsoft" ms)
269 (const :tag "MySQL" mysql)
270 (const :tag "Oracle" oracle)
271 (const :tag "PostGres" postgres)
272 (const :tag "Solid" solid)
273 (const :tag "SQLite" sqlite)
274 (const :tag "Sybase" sybase))
275 :group 'SQL)
277 (defvar sql-interactive-product nil
278 "Product under `sql-interactive-mode'.")
280 (defvar sql-product-alist
281 '((ansi
282 :font-lock sql-mode-ansi-font-lock-keywords)
283 (db2
284 :font-lock sql-mode-db2-font-lock-keywords
285 :sqli-login nil
286 :sqli-connect sql-connect-db2
287 :sqli-prompt-regexp "^db2 => "
288 :sqli-prompt-length 7)
289 (informix
290 :font-lock sql-mode-informix-font-lock-keywords
291 :sqli-login (database)
292 :sqli-connect sql-connect-informix
293 :sqli-prompt-regexp "^SQL> "
294 :sqli-prompt-length 5)
295 (ingres
296 :font-lock sql-mode-ingres-font-lock-keywords
297 :sqli-login (database)
298 :sqli-connect sql-connect-ingres
299 :sqli-prompt-regexp "^\* "
300 :sqli-prompt-length 2)
301 (interbase
302 :font-lock sql-mode-interbase-font-lock-keywords
303 :sqli-login (user password database)
304 :sqli-connect sql-connect-interbase
305 :sqli-prompt-regexp "^SQL> "
306 :sqli-prompt-length 5)
307 (linter
308 :font-lock sql-mode-linter-font-lock-keywords
309 :sqli-login (user password database server)
310 :sqli-connect sql-connect-linter
311 :sqli-prompt-regexp "^SQL>"
312 :sqli-prompt-length 4)
314 :font-lock sql-mode-ms-font-lock-keywords
315 :sqli-login (user password server database)
316 :sqli-connect sql-connect-ms
317 :sqli-prompt-regexp "^[0-9]*>"
318 :sqli-prompt-length 5
319 :syntax-alist ((?@ . "w")))
320 (mysql
321 :font-lock sql-mode-mysql-font-lock-keywords
322 :sqli-login (user password database server)
323 :sqli-connect sql-connect-mysql
324 :sqli-prompt-regexp "^mysql> "
325 :sqli-prompt-length 6)
326 (oracle
327 :font-lock sql-mode-oracle-font-lock-keywords
328 :sqli-login (user password database)
329 :sqli-connect sql-connect-oracle
330 :sqli-prompt-regexp "^SQL> "
331 :sqli-prompt-length 5
332 :syntax-alist ((?$ . "w") (?# . "w")))
333 (postgres
334 :font-lock sql-mode-postgres-font-lock-keywords
335 :sqli-login (user database server)
336 :sqli-connect sql-connect-postgres
337 :sqli-prompt-regexp "^.*[#>] *"
338 :sqli-prompt-length 5)
339 (solid
340 :font-lock sql-mode-solid-font-lock-keywords
341 :sqli-login (user password server)
342 :sqli-connect sql-connect-solid
343 :sqli-prompt-regexp "^"
344 :sqli-prompt-length 0)
345 (sqlite
346 :font-lock sql-mode-sqlite-font-lock-keywords
347 :sqli-login (user password server database)
348 :sqli-connect sql-connect-sqlite
349 :sqli-prompt-regexp "^sqlite> "
350 :sqli-prompt-length 8)
351 (sybase
352 :font-lock sql-mode-sybase-font-lock-keywords
353 :sqli-login (server user password database)
354 :sqli-connect sql-connect-sybase
355 :sqli-prompt-regexp "^SQL> "
356 :sqli-prompt-length 5
357 :syntax-alist ((?@ . "w")))
359 "This variable contains a list of product features for each of the
360 SQL products handled by `sql-mode'. Without an entry in this list a
361 product will not be properly highlighted and will not support
362 `sql-interactive-mode'.
364 Each element in the list is in the following format:
366 \(PRODUCT FEATURE VALUE ...)
368 where PRODUCT is the appropriate value of `sql-product'. The product
369 name is then followed by FEATURE-VALUE pairs. If a FEATURE is not
370 specified, its VALUE is treated as nil. FEATURE must be one of the
371 following:
373 :font-lock name of the variable containing the product
374 specific font lock highlighting patterns.
376 :sqli-login a list of login parameters (i.e., user,
377 password, database and server) needed to
378 connect to the database.
380 :sqli-connect the name of a function which accepts no
381 parameters that will use the values of
382 `sql-user', `sql-password',
383 `sql-database' and `sql-server' to open a
384 comint buffer and connect to the
385 database. Do product specific
386 configuration of comint in this function.
388 :sqli-prompt-regexp a regular expression string that matches
389 the prompt issued by the product
390 interpreter. (Not needed in 21.3+)
392 :sqli-prompt-length the length of the prompt on the line.(Not
393 needed in 21.3+)
395 :syntax-alist an alist of syntax table entries to enable
396 special character treatment by font-lock and
397 imenu. ")
399 ;; misc customization of sql.el behaviour
401 (defcustom sql-electric-stuff nil
402 "Treat some input as electric.
403 If set to the symbol `semicolon', then hitting `;' will send current
404 input in the SQLi buffer to the process.
405 If set to the symbol `go', then hitting `go' on a line by itself will
406 send current input in the SQLi buffer to the process.
407 If set to nil, then you must use \\[comint-send-input] in order to send
408 current input in the SQLi buffer to the process."
409 :type '(choice (const :tag "Nothing" nil)
410 (const :tag "The semikolon `;'" semicolon)
411 (const :tag "The string `go' by itself" go))
412 :version "20.8"
413 :group 'SQL)
415 (defcustom sql-pop-to-buffer-after-send-region nil
416 "*If t, pop to the buffer SQL statements are sent to.
418 After a call to `sql-send-region' or `sql-send-buffer',
419 the window is split and the SQLi buffer is shown. If this
420 variable is not nil, that buffer's window will be selected
421 by calling `pop-to-buffer'. If this variable is nil, that
422 buffer is shown using `display-buffer'."
423 :type 'boolean
424 :group 'SQL)
426 ;; imenu support for sql-mode.
428 (defvar sql-imenu-generic-expression
429 ;; Items are in reverse order because they are rendered in reverse.
430 '(("Rules/Defaults" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(rule\\|default\\)\\s-+\\(\\w+\\)" 3)
431 ("Sequences" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*sequence\\s-+\\(\\w+\\)" 2)
432 ("Triggers" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*trigger\\s-+\\(\\w+\\)" 2)
433 ("Functions" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?function\\s-+\\(\\w+\\)" 3)
434 ("Procedures" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4)
435 ("Packages" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3)
436 ("Indexes" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*index\\s-+\\(\\w+\\)" 2)
437 ("Tables/Views" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(table\\|view\\)\\s-+\\(\\w+\\)" 3))
438 "Define interesting points in the SQL buffer for `imenu'.
440 This is used to set `imenu-generic-expression' when SQL mode is
441 entered. Subsequent changes to sql-imenu-generic-expression will not
442 affect existing SQL buffers because imenu-generic-expression is a
443 local variable.")
445 ;; history file
447 (defcustom sql-input-ring-file-name nil
448 "*If non-nil, name of the file to read/write input history.
450 You have to set this variable if you want the history of your commands
451 saved from one Emacs session to the next. If this variable is set,
452 exiting the SQL interpreter in an SQLi buffer will write the input
453 history to the specified file. Starting a new process in a SQLi buffer
454 will read the input history from the specified file.
456 This is used to initialize `comint-input-ring-file-name'.
458 Note that the size of the input history is determined by the variable
459 `comint-input-ring-size'."
460 :type '(choice (const :tag "none" nil)
461 (file))
462 :group 'SQL)
464 (defcustom sql-input-ring-separator "\n--\n"
465 "*Separator between commands in the history file.
467 If set to \"\\n\", each line in the history file will be interpreted as
468 one command. Multi-line commands are split into several commands when
469 the input ring is initialized from a history file.
471 This variable used to initialize `comint-input-ring-separator'.
472 `comint-input-ring-separator' is part of Emacs 21; if your Emacs
473 does not have it, setting `sql-input-ring-separator' will have no
474 effect. In that case multiline commands will be split into several
475 commands when the input history is read, as if you had set
476 `sql-input-ring-separator' to \"\\n\"."
477 :type 'string
478 :group 'SQL)
480 ;; The usual hooks
482 (defcustom sql-interactive-mode-hook '()
483 "*Hook for customizing `sql-interactive-mode'."
484 :type 'hook
485 :group 'SQL)
487 (defcustom sql-mode-hook '()
488 "*Hook for customizing `sql-mode'."
489 :type 'hook
490 :group 'SQL)
492 (defcustom sql-set-sqli-hook '()
493 "*Hook for reacting to changes of `sql-buffer'.
495 This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
496 is changed."
497 :type 'hook
498 :group 'SQL)
500 ;; Customization for Oracle
502 (defcustom sql-oracle-program "sqlplus"
503 "*Command to start sqlplus by Oracle.
505 Starts `sql-interactive-mode' after doing some setup.
507 Under NT, \"sqlplus\" usually starts the sqlplus \"GUI\". In order to
508 start the sqlplus console, use \"plus33\" or something similar. You
509 will find the file in your Orant\\bin directory.
511 The program can also specify a TCP connection. See `make-comint'."
512 :type 'file
513 :group 'SQL)
515 (defcustom sql-oracle-options nil
516 "*List of additional options for `sql-oracle-program'."
517 :type '(repeat string)
518 :version "20.8"
519 :group 'SQL)
521 ;; Customization for SQLite
523 (defcustom sql-sqlite-program "sqlite"
524 "*Command to start SQLite.
526 Starts `sql-interactive-mode' after doing some setup.
528 The program can also specify a TCP connection. See `make-comint'."
529 :type 'file
530 :group 'SQL)
532 (defcustom sql-sqlite-options nil
533 "*List of additional options for `sql-sqlite-program'.
534 The following list of options is reported to make things work
535 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
536 :type '(repeat string)
537 :version "20.8"
538 :group 'SQL)
540 ;; Customization for MySql
542 (defcustom sql-mysql-program "mysql"
543 "*Command to start mysql by TcX.
545 Starts `sql-interactive-mode' after doing some setup.
547 The program can also specify a TCP connection. See `make-comint'."
548 :type 'file
549 :group 'SQL)
551 (defcustom sql-mysql-options nil
552 "*List of additional options for `sql-mysql-program'.
553 The following list of options is reported to make things work
554 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
555 :type '(repeat string)
556 :version "20.8"
557 :group 'SQL)
559 ;; Customization for Solid
561 (defcustom sql-solid-program "solsql"
562 "*Command to start SOLID SQL Editor.
564 Starts `sql-interactive-mode' after doing some setup.
566 The program can also specify a TCP connection. See `make-comint'."
567 :type 'file
568 :group 'SQL)
570 ;; Customization for SyBase
572 (defcustom sql-sybase-program "isql"
573 "*Command to start isql by SyBase.
575 Starts `sql-interactive-mode' after doing some setup.
577 The program can also specify a TCP connection. See `make-comint'."
578 :type 'file
579 :group 'SQL)
581 (defcustom sql-sybase-options nil
582 "*List of additional options for `sql-sybase-program'.
583 Some versions of isql might require the -n option in order to work."
584 :type '(repeat string)
585 :version "20.8"
586 :group 'SQL)
588 ;; Customization for Informix
590 (defcustom sql-informix-program "dbaccess"
591 "*Command to start dbaccess by Informix.
593 Starts `sql-interactive-mode' after doing some setup.
595 The program can also specify a TCP connection. See `make-comint'."
596 :type 'file
597 :group 'SQL)
599 ;; Customization for Ingres
601 (defcustom sql-ingres-program "sql"
602 "*Command to start sql by Ingres.
604 Starts `sql-interactive-mode' after doing some setup.
606 The program can also specify a TCP connection. See `make-comint'."
607 :type 'file
608 :group 'SQL)
610 ;; Customization for Microsoft
612 (defcustom sql-ms-program "osql"
613 "*Command to start osql by Microsoft.
615 Starts `sql-interactive-mode' after doing some setup.
617 The program can also specify a TCP connection. See `make-comint'."
618 :type 'file
619 :group 'SQL)
621 (defcustom sql-ms-options '("-w" "300" "-n")
622 ;; -w is the linesize
623 "*List of additional options for `sql-ms-program'."
624 :type '(repeat string)
625 :version "22.1"
626 :group 'SQL)
628 ;; Customization for Postgres
630 (defcustom sql-postgres-program "psql"
631 "Command to start psql by Postgres.
633 Starts `sql-interactive-mode' after doing some setup.
635 The program can also specify a TCP connection. See `make-comint'."
636 :type 'file
637 :group 'SQL)
639 (defcustom sql-postgres-options '("-P" "pager=off")
640 "*List of additional options for `sql-postgres-program'.
641 The default setting includes the -P option which breaks older versions
642 of the psql client (such as version 6.5.3). The -P option is equivalent
643 to the --pset option. If you want the psql to prompt you for a user
644 name, add the string \"-u\" to the list of options. If you want to
645 provide a user name on the command line (newer versions such as 7.1),
646 add your name with a \"-U\" prefix (such as \"-Umark\") to the list."
647 :type '(repeat string)
648 :version "20.8"
649 :group 'SQL)
651 ;; Customization for Interbase
653 (defcustom sql-interbase-program "isql"
654 "*Command to start isql by Interbase.
656 Starts `sql-interactive-mode' after doing some setup.
658 The program can also specify a TCP connection. See `make-comint'."
659 :type 'file
660 :group 'SQL)
662 (defcustom sql-interbase-options nil
663 "*List of additional options for `sql-interbase-program'."
664 :type '(repeat string)
665 :version "20.8"
666 :group 'SQL)
668 ;; Customization for DB2
670 (defcustom sql-db2-program "db2"
671 "*Command to start db2 by IBM.
673 Starts `sql-interactive-mode' after doing some setup.
675 The program can also specify a TCP connection. See `make-comint'."
676 :type 'file
677 :group 'SQL)
679 (defcustom sql-db2-options nil
680 "*List of additional options for `sql-db2-program'."
681 :type '(repeat string)
682 :version "20.8"
683 :group 'SQL)
685 ;; Customization for Linter
687 (defcustom sql-linter-program "inl"
688 "*Command to start inl by RELEX.
690 Starts `sql-interactive-mode' after doing some setup."
691 :type 'file
692 :group 'SQL)
694 (defcustom sql-linter-options nil
695 "*List of additional options for `sql-linter-program'."
696 :type '(repeat string)
697 :version "21.3"
698 :group 'SQL)
702 ;;; Variables which do not need customization
704 (defvar sql-user-history nil
705 "History of usernames used.")
707 (defvar sql-database-history nil
708 "History of databases used.")
710 (defvar sql-server-history nil
711 "History of servers used.")
713 ;; Passwords are not kept in a history.
715 (defvar sql-buffer nil
716 "Current SQLi buffer.
718 The global value of sql-buffer is the name of the latest SQLi buffer
719 created. Any SQL buffer created will make a local copy of this value.
720 See `sql-interactive-mode' for more on multiple sessions. If you want
721 to change the SQLi buffer a SQL mode sends its SQL strings to, change
722 the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
724 (defvar sql-prompt-regexp nil
725 "Prompt used to initialize `comint-prompt-regexp'.
727 You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.")
729 (defvar sql-prompt-length 0
730 "Prompt used to set `left-margin' in `sql-interactive-mode'.
732 You can change `sql-prompt-length' on `sql-interactive-mode-hook'.")
734 (defvar sql-alternate-buffer-name nil
735 "Buffer-local string used to possibly rename the SQLi buffer.
737 Used by `sql-rename-buffer'.")
739 ;; Keymap for sql-interactive-mode.
741 (defvar sql-interactive-mode-map
742 (let ((map (make-sparse-keymap)))
743 (if (fboundp 'set-keymap-parent)
744 (set-keymap-parent map comint-mode-map); Emacs
745 (if (fboundp 'set-keymap-parents)
746 (set-keymap-parents map (list comint-mode-map)))); XEmacs
747 (if (fboundp 'set-keymap-name)
748 (set-keymap-name map 'sql-interactive-mode-map)); XEmacs
749 (define-key map (kbd "C-j") 'sql-accumulate-and-indent)
750 (define-key map (kbd "C-c C-w") 'sql-copy-column)
751 (define-key map (kbd "O") 'sql-magic-go)
752 (define-key map (kbd "o") 'sql-magic-go)
753 (define-key map (kbd ";") 'sql-magic-semicolon)
754 map)
755 "Mode map used for `sql-interactive-mode'.
756 Based on `comint-mode-map'.")
758 ;; Keymap for sql-mode.
760 (defvar sql-mode-map
761 (let ((map (make-sparse-keymap)))
762 (define-key map (kbd "C-c C-c") 'sql-send-paragraph)
763 (define-key map (kbd "C-c C-r") 'sql-send-region)
764 (define-key map (kbd "C-c C-s") 'sql-send-string)
765 (define-key map (kbd "C-c C-b") 'sql-send-buffer)
766 map)
767 "Mode map used for `sql-mode'.")
769 ;; easy menu for sql-mode.
771 (easy-menu-define
772 sql-mode-menu sql-mode-map
773 "Menu for `sql-mode'."
774 '("SQL"
775 ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer)
776 (get-buffer-process sql-buffer))]
777 ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs
778 mark-active)
779 (mark t)); XEmacs
780 (buffer-live-p sql-buffer)
781 (get-buffer-process sql-buffer))]
782 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)
783 (get-buffer-process sql-buffer))]
784 ["Send String" sql-send-string t]
785 ["--" nil nil]
786 ["Start SQLi session" sql-product-interactive (sql-product-feature :sqli-connect)]
787 ["Show SQLi buffer" sql-show-sqli-buffer t]
788 ["Set SQLi buffer" sql-set-sqli-buffer t]
789 ["Pop to SQLi buffer after send"
790 sql-toggle-pop-to-buffer-after-send-region
791 :style toggle
792 :selected sql-pop-to-buffer-after-send-region]
793 ["--" nil nil]
794 ("Product"
795 ["ANSI" sql-highlight-ansi-keywords
796 :style radio
797 :selected (eq sql-product 'ansi)]
798 ["DB2" sql-highlight-db2-keywords
799 :style radio
800 :selected (eq sql-product 'db2)]
801 ["Informix" sql-highlight-informix-keywords
802 :style radio
803 :selected (eq sql-product 'informix)]
804 ["Ingres" sql-highlight-ingres-keywords
805 :style radio
806 :selected (eq sql-product 'ingres)]
807 ["Interbase" sql-highlight-interbase-keywords
808 :style radio
809 :selected (eq sql-product 'interbase)]
810 ["Linter" sql-highlight-linter-keywords
811 :style radio
812 :selected (eq sql-product 'linter)]
813 ["MS SQLServer" sql-highlight-ms-keywords
814 :style radio
815 :selected (eq sql-product 'ms)]
816 ["MySQL" sql-highlight-mysql-keywords
817 :style radio
818 :selected (eq sql-product 'mysql)]
819 ["Oracle" sql-highlight-oracle-keywords
820 :style radio
821 :selected (eq sql-product 'oracle)]
822 ["Postgres" sql-highlight-postgres-keywords
823 :style radio
824 :selected (eq sql-product 'postgres)]
825 ["Solid" sql-highlight-solid-keywords
826 :style radio
827 :selected (eq sql-product 'solid)]
828 ["SQLite" sql-highlight-sqlite-keywords
829 :style radio
830 :selected (eq sql-product 'sqlite)]
831 ["Sybase" sql-highlight-sybase-keywords
832 :style radio
833 :selected (eq sql-product 'sybase)]
836 ;; easy menu for sql-interactive-mode.
838 (easy-menu-define
839 sql-interactive-mode-menu sql-interactive-mode-map
840 "Menu for `sql-interactive-mode'."
841 '("SQL"
842 ["Rename Buffer" sql-rename-buffer t]))
844 ;; Abbreviations -- if you want more of them, define them in your
845 ;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too.
847 (defvar sql-mode-abbrev-table nil
848 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")
849 (unless sql-mode-abbrev-table
850 (define-abbrev-table 'sql-mode-abbrev-table nil)
851 (mapcar
852 ;; In Emacs 21.3+, provide SYSTEM-FLAG to define-abbrev.
853 '(lambda (abbrev)
854 (let ((name (car abbrev))
855 (expansion (cdr abbrev)))
856 (condition-case nil
857 (define-abbrev sql-mode-abbrev-table name expansion nil 0 t)
858 (error
859 (define-abbrev sql-mode-abbrev-table name expansion)))))
860 '(("ins" "insert")
861 ("upd" "update")
862 ("del" "delete")
863 ("sel" "select")
864 ("proc" "procedure")
865 ("func" "function")
866 ("cr" "create"))))
868 ;; Syntax Table
870 (defvar sql-mode-syntax-table
871 (let ((table (make-syntax-table)))
872 ;; C-style comments /**/ (see elisp manual "Syntax Flags"))
873 (modify-syntax-entry ?/ ". 14" table)
874 (modify-syntax-entry ?* ". 23" table)
875 ;; double-dash starts comment
876 (modify-syntax-entry ?- ". 12b" table)
877 ;; newline and formfeed end coments
878 (modify-syntax-entry ?\n "> b" table)
879 (modify-syntax-entry ?\f "> b" table)
880 ;; single quotes (') quotes delimit strings
881 (modify-syntax-entry ?' "\"" table)
882 ;; backslash is no escape character
883 (modify-syntax-entry ?\\ "." table)
884 table)
885 "Syntax table used in `sql-mode' and `sql-interactive-mode'.")
887 ;; Font lock support
889 (defvar sql-mode-font-lock-object-name
890 (list (concat "^\\s-*\\(create\\|drop\\|alter\\)\\s-+" ;; lead off with CREATE, DROP or ALTER
891 "\\(\\w+\\s-+\\)*" ;; optional intervening keywords
892 "\\(table\\|view\\|package\\(\\s-+body\\)?\\|proc\\(edure\\)?"
893 "\\|function\\|trigger\\|sequence\\|rule\\|default\\)\\s-+"
894 "\\(\\w+\\)")
895 6 'font-lock-function-name-face)
897 "Pattern to match the names of top-level objects.
899 The pattern matches the name in a CREATE, DROP or ALTER
900 statement. The format of variable should be a valid
901 `font-lock-keywords' entry.")
903 (defmacro sql-keywords-re (&rest keywords)
904 "Compile-time generation of regexp matching any one of KEYWORDS."
905 `(eval-when-compile
906 (concat "\\b"
907 (regexp-opt ',keywords t)
908 "\\b")))
910 (defvar sql-mode-ansi-font-lock-keywords
911 (let ((ansi-funcs (sql-keywords-re
912 "abs" "avg" "bit_length" "cardinality" "cast" "char_length"
913 "character_length" "coalesce" "convert" "count" "current_date"
914 "current_path" "current_role" "current_time" "current_timestamp"
915 "current_user" "extract" "localtime" "localtimestamp" "lower" "max"
916 "min" "mod" "nullif" "octet_length" "overlay" "placing" "session_user"
917 "substring" "sum" "system_user" "translate" "treat" "trim" "upper"
918 "user"
921 (ansi-non-reserved (sql-keywords-re
922 "ada" "asensitive" "assignment" "asymmetric" "atomic" "between"
923 "bitvar" "called" "catalog_name" "chain" "character_set_catalog"
924 "character_set_name" "character_set_schema" "checked" "class_origin"
925 "cobol" "collation_catalog" "collation_name" "collation_schema"
926 "column_name" "command_function" "command_function_code" "committed"
927 "condition_number" "connection_name" "constraint_catalog"
928 "constraint_name" "constraint_schema" "contains" "cursor_name"
929 "datetime_interval_code" "datetime_interval_precision" "defined"
930 "definer" "dispatch" "dynamic_function" "dynamic_function_code"
931 "existing" "exists" "final" "fortran" "generated" "granted"
932 "hierarchy" "hold" "implementation" "infix" "insensitive" "instance"
933 "instantiable" "invoker" "key_member" "key_type" "length" "m"
934 "message_length" "message_octet_length" "message_text" "method" "more"
935 "mumps" "name" "nullable" "number" "options" "overlaps" "overriding"
936 "parameter_mode" "parameter_name" "parameter_ordinal_position"
937 "parameter_specific_catalog" "parameter_specific_name"
938 "parameter_specific_schema" "pascal" "pli" "position" "repeatable"
939 "returned_length" "returned_octet_length" "returned_sqlstate"
940 "routine_catalog" "routine_name" "routine_schema" "row_count" "scale"
941 "schema_name" "security" "self" "sensitive" "serializable"
942 "server_name" "similar" "simple" "source" "specific_name" "style"
943 "subclass_origin" "sublist" "symmetric" "system" "table_name"
944 "transaction_active" "transactions_committed"
945 "transactions_rolled_back" "transform" "transforms" "trigger_catalog"
946 "trigger_name" "trigger_schema" "type" "uncommitted" "unnamed"
947 "user_defined_type_catalog" "user_defined_type_name"
948 "user_defined_type_schema"
951 (ansi-reserved (sql-keywords-re
952 "absolute" "action" "add" "admin" "after" "aggregate" "alias" "all"
953 "allocate" "alter" "and" "any" "are" "as" "asc" "assertion" "at"
954 "authorization" "before" "begin" "both" "breadth" "by" "call"
955 "cascade" "cascaded" "case" "catalog" "check" "class" "close"
956 "collate" "collation" "column" "commit" "completion" "connect"
957 "connection" "constraint" "constraints" "constructor" "continue"
958 "corresponding" "create" "cross" "cube" "current" "cursor" "cycle"
959 "data" "day" "deallocate" "declare" "default" "deferrable" "deferred"
960 "delete" "depth" "deref" "desc" "describe" "descriptor" "destroy"
961 "destructor" "deterministic" "diagnostics" "dictionary" "disconnect"
962 "distinct" "domain" "drop" "dynamic" "each" "else" "end" "equals"
963 "escape" "every" "except" "exception" "exec" "execute" "external"
964 "false" "fetch" "first" "for" "foreign" "found" "free" "from" "full"
965 "function" "general" "get" "global" "go" "goto" "grant" "group"
966 "grouping" "having" "host" "hour" "identity" "ignore" "immediate" "in"
967 "indicator" "initialize" "initially" "inner" "inout" "input" "insert"
968 "intersect" "into" "is" "isolation" "iterate" "join" "key" "language"
969 "last" "lateral" "leading" "left" "less" "level" "like" "limit"
970 "local" "locator" "map" "match" "minute" "modifies" "modify" "module"
971 "month" "names" "natural" "new" "next" "no" "none" "not" "null" "of"
972 "off" "old" "on" "only" "open" "operation" "option" "or" "order"
973 "ordinality" "out" "outer" "output" "pad" "parameter" "parameters"
974 "partial" "path" "postfix" "prefix" "preorder" "prepare" "preserve"
975 "primary" "prior" "privileges" "procedure" "public" "read" "reads"
976 "recursive" "references" "referencing" "relative" "restrict" "result"
977 "return" "returns" "revoke" "right" "role" "rollback" "rollup"
978 "routine" "rows" "savepoint" "schema" "scroll" "search" "second"
979 "section" "select" "sequence" "session" "set" "sets" "size" "some"
980 "space" "specific" "specifictype" "sql" "sqlexception" "sqlstate"
981 "sqlwarning" "start" "state" "statement" "static" "structure" "table"
982 "temporary" "terminate" "than" "then" "timezone_hour"
983 "timezone_minute" "to" "trailing" "transaction" "translation"
984 "trigger" "true" "under" "union" "unique" "unknown" "unnest" "update"
985 "usage" "using" "value" "values" "variable" "view" "when" "whenever"
986 "where" "with" "without" "work" "write" "year"
989 (ansi-types (sql-keywords-re
990 "array" "binary" "bit" "blob" "boolean" "char" "character" "clob"
991 "date" "dec" "decimal" "double" "float" "int" "integer" "interval"
992 "large" "national" "nchar" "nclob" "numeric" "object" "precision"
993 "real" "ref" "row" "scope" "smallint" "time" "timestamp" "varchar"
994 "varying" "zone"
997 `((,ansi-non-reserved . font-lock-keyword-face)
998 (,ansi-reserved . font-lock-keyword-face)
999 (,ansi-funcs . font-lock-builtin-face)
1000 (,ansi-types . font-lock-type-face)))
1002 "ANSI SQL keywords used by font-lock.
1004 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1005 regular expressions are created during compilation by calling the
1006 function `regexp-opt'. Therefore, take a look at the source before
1007 you define your own sql-mode-ansi-font-lock-keywords. You may want to
1008 add functions and PL/SQL keywords.")
1010 (defvar sql-mode-oracle-font-lock-keywords
1011 (let ((oracle-functions (sql-keywords-re
1012 "abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2"
1013 "avg" "bfilename" "bin_to_num" "bitand" "cast" "ceil" "chartorowid"
1014 "chr" "coalesce" "compose" "concat" "convert" "corr" "cos" "cosh"
1015 "count" "covar_pop" "covar_samp" "cume_dist" "current_date"
1016 "current_timestamp" "current_user" "dbtimezone" "decode" "decompose"
1017 "dense_rank" "depth" "deref" "dump" "empty_clob" "existsnode" "exp"
1018 "extract" "extractvalue" "first" "first_value" "floor" "following"
1019 "from_tz" "greatest" "group_id" "grouping_id" "hextoraw" "initcap"
1020 "instr" "lag" "last" "last_day" "last_value" "lead" "least" "length"
1021 "ln" "localtimestamp" "lower" "lpad" "ltrim" "make_ref" "max" "min"
1022 "mod" "months_between" "new_time" "next_day" "nls_charset_decl_len"
1023 "nls_charset_id" "nls_charset_name" "nls_initcap" "nls_lower"
1024 "nls_upper" "nlssort" "ntile" "nullif" "numtodsinterval"
1025 "numtoyminterval" "nvl" "nvl2" "over" "path" "percent_rank"
1026 "percentile_cont" "percentile_disc" "power" "preceding" "rank"
1027 "ratio_to_report" "rawtohex" "rawtonhex" "reftohex" "regr_"
1028 "regr_avgx" "regr_avgy" "regr_count" "regr_intercept" "regr_r2"
1029 "regr_slope" "regr_sxx" "regr_sxy" "regr_syy" "replace" "round"
1030 "row_number" "rowidtochar" "rowidtonchar" "rpad" "rtrim"
1031 "sessiontimezone" "sign" "sin" "sinh" "soundex" "sqrt" "stddev"
1032 "stddev_pop" "stddev_samp" "substr" "sum" "sys_connect_by_path"
1033 "sys_context" "sys_dburigen" "sys_extract_utc" "sys_guid" "sys_typeid"
1034 "sys_xmlagg" "sys_xmlgen" "sysdate" "systimestamp" "tan" "tanh"
1035 "to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte"
1036 "to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp"
1037 "to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc"
1038 "tz_offset" "uid" "unbounded" "unistr" "updatexml" "upper" "user"
1039 "userenv" "var_pop" "var_samp" "variance" "vsize" "width_bucket" "xml"
1040 "xmlagg" "xmlattribute" "xmlcolattval" "xmlconcat" "xmlelement"
1041 "xmlforest" "xmlsequence" "xmltransform"
1044 (oracle-keywords (sql-keywords-re
1045 "abort" "access" "accessed" "account" "activate" "add" "admin"
1046 "advise" "after" "agent" "aggregate" "all" "allocate" "allow" "alter"
1047 "always" "analyze" "ancillary" "and" "any" "apply" "archive"
1048 "archivelog" "array" "as" "asc" "associate" "at" "attribute"
1049 "attributes" "audit" "authenticated" "authid" "authorization" "auto"
1050 "autoallocate" "automatic" "availability" "backup" "before" "begin"
1051 "behalf" "between" "binding" "bitmap" "block" "blocksize" "body"
1052 "both" "buffer_pool" "build" "by" "cache" "call" "cancel"
1053 "cascade" "case" "category" "certificate" "chained" "change" "check"
1054 "checkpoint" "child" "chunk" "class" "clear" "clone" "close" "cluster"
1055 "column" "column_value" "columns" "comment" "commit" "committed"
1056 "compatibility" "compile" "complete" "composite_limit" "compress"
1057 "compute" "connect" "connect_time" "consider" "consistent"
1058 "constraint" "constraints" "constructor" "contents" "context"
1059 "continue" "controlfile" "corruption" "cost" "cpu_per_call"
1060 "cpu_per_session" "create" "cross" "cube" "current" "currval" "cycle"
1061 "dangling" "data" "database" "datafile" "datafiles" "day" "ddl"
1062 "deallocate" "debug" "default" "deferrable" "deferred" "definer"
1063 "delay" "delete" "demand" "desc" "determines" "deterministic"
1064 "dictionary" "dimension" "directory" "disable" "disassociate"
1065 "disconnect" "distinct" "distinguished" "distributed" "dml" "drop"
1066 "each" "element" "else" "enable" "end" "equals_path" "escape"
1067 "estimate" "except" "exceptions" "exchange" "excluding" "exists"
1068 "expire" "explain" "extent" "external" "externally"
1069 "failed_login_attempts" "fast" "file" "final" "finish" "flush" "for"
1070 "force" "foreign" "freelist" "freelists" "freepools" "fresh" "from"
1071 "full" "function" "functions" "generated" "global" "global_name"
1072 "globally" "grant" "group" "grouping" "groups" "guard" "hash"
1073 "hashkeys" "having" "heap" "hierarchy" "id" "identified" "identifier"
1074 "idle_time" "immediate" "in" "including" "increment" "index" "indexed"
1075 "indexes" "indextype" "indextypes" "indicator" "initial" "initialized"
1076 "initially" "initrans" "inner" "insert" "instance" "instantiable"
1077 "instead" "intersect" "into" "invalidate" "is" "isolation" "java"
1078 "join" "keep" "key" "kill" "language" "left" "less" "level"
1079 "levels" "library" "like" "like2" "like4" "likec" "limit" "link"
1080 "list" "lob" "local" "location" "locator" "lock" "log" "logfile"
1081 "logging" "logical" "logical_reads_per_call"
1082 "logical_reads_per_session" "managed" "management" "manual" "map"
1083 "mapping" "master" "matched" "materialized" "maxdatafiles"
1084 "maxextents" "maximize" "maxinstances" "maxlogfiles" "maxloghistory"
1085 "maxlogmembers" "maxsize" "maxtrans" "maxvalue" "member" "memory"
1086 "merge" "migrate" "minextents" "minimize" "minimum" "minus" "minvalue"
1087 "mode" "modify" "monitoring" "month" "mount" "move" "movement" "name"
1088 "named" "natural" "nested" "never" "new" "next" "nextval" "no"
1089 "noarchivelog" "noaudit" "nocache" "nocompress" "nocopy" "nocycle"
1090 "nodelay" "noforce" "nologging" "nomapping" "nomaxvalue" "nominimize"
1091 "nominvalue" "nomonitoring" "none" "noorder" "noparallel" "norely"
1092 "noresetlogs" "noreverse" "normal" "norowdependencies" "nosort"
1093 "noswitch" "not" "nothing" "notimeout" "novalidate" "nowait" "null"
1094 "nulls" "object" "of" "off" "offline" "oidindex" "old" "on" "online"
1095 "only" "open" "operator" "optimal" "option" "or" "order"
1096 "organization" "out" "outer" "outline" "overflow" "overriding"
1097 "package" "packages" "parallel" "parallel_enable" "parameters"
1098 "parent" "partition" "partitions" "password" "password_grace_time"
1099 "password_life_time" "password_lock_time" "password_reuse_max"
1100 "password_reuse_time" "password_verify_function" "pctfree"
1101 "pctincrease" "pctthreshold" "pctused" "pctversion" "percent"
1102 "performance" "permanent" "pfile" "physical" "pipelined" "plan"
1103 "post_transaction" "pragma" "prebuilt" "preserve" "primary" "private"
1104 "private_sga" "privileges" "procedure" "profile" "protection" "public"
1105 "purge" "query" "quiesce" "quota" "range" "read" "reads" "rebuild"
1106 "records_per_block" "recover" "recovery" "recycle" "reduced" "ref"
1107 "references" "referencing" "refresh" "register" "reject" "relational"
1108 "rely" "rename" "reset" "resetlogs" "resize" "resolve" "resolver"
1109 "resource" "restrict" "restrict_references" "restricted" "result"
1110 "resumable" "resume" "retention" "return" "returning" "reuse"
1111 "reverse" "revoke" "rewrite" "right" "rnds" "rnps" "role" "roles"
1112 "rollback" "rollup" "row" "rowdependencies" "rownum" "rows" "sample"
1113 "savepoint" "scan" "schema" "scn" "scope" "segment" "select"
1114 "selectivity" "self" "sequence" "serializable" "session"
1115 "sessions_per_user" "set" "sets" "settings" "shared" "shared_pool"
1116 "shrink" "shutdown" "siblings" "sid" "single" "size" "skip" "some"
1117 "sort" "source" "space" "specification" "spfile" "split" "standby"
1118 "start" "statement_id" "static" "statistics" "stop" "storage" "store"
1119 "structure" "subpartition" "subpartitions" "substitutable"
1120 "successful" "supplemental" "suspend" "switch" "switchover" "synonym"
1121 "sys" "system" "table" "tables" "tablespace" "tempfile" "template"
1122 "temporary" "test" "than" "then" "thread" "through" "time_zone"
1123 "timeout" "to" "trace" "transaction" "trigger" "triggers" "truncate"
1124 "trust" "type" "types" "unarchived" "under" "under_path" "undo"
1125 "uniform" "union" "unique" "unlimited" "unlock" "unquiesce"
1126 "unrecoverable" "until" "unusable" "unused" "update" "upgrade" "usage"
1127 "use" "using" "validate" "validation" "value" "values" "variable"
1128 "varray" "version" "view" "wait" "when" "whenever" "where" "with"
1129 "without" "wnds" "wnps" "work" "write" "xmldata" "xmlschema" "xmltype"
1132 (oracle-types (sql-keywords-re
1133 "bfile" "blob" "byte" "char" "character" "clob" "date" "dec" "decimal"
1134 "double" "float" "int" "integer" "interval" "long" "national" "nchar"
1135 "nclob" "number" "numeric" "nvarchar2" "precision" "raw" "real"
1136 "rowid" "second" "smallint" "time" "timestamp" "urowid" "varchar"
1137 "varchar2" "varying" "year" "zone"
1140 (plsql-functions (sql-keywords-re
1141 "%bulk_rowcount" "%found" "%isopen" "%notfound" "%rowcount" "%rowtype"
1142 "%type" "extend" "prior"
1145 (plsql-keywords (sql-keywords-re
1146 "autonomous_transaction" "bulk" "char_base" "collect" "constant"
1147 "cursor" "declare" "do" "elsif" "exception_init" "execute" "exit"
1148 "extends" "false" "fetch" "forall" "goto" "hour" "if" "interface"
1149 "loop" "minute" "number_base" "ocirowid" "opaque" "others" "rowtype"
1150 "separate" "serially_reusable" "sql" "sqlcode" "sqlerrm" "subtype"
1151 "the" "timezone_abbr" "timezone_hour" "timezone_minute"
1152 "timezone_region" "true" "varrying" "while"
1155 (plsql-type (sql-keywords-re
1156 "binary_integer" "boolean" "naturaln" "pls_integer" "positive"
1157 "positiven" "record" "signtype" "string"
1160 (plsql-warning (sql-keywords-re
1161 "access_into_null" "case_not_found" "collection_is_null"
1162 "cursor_already_open" "dup_val_on_index" "invalid_cursor"
1163 "invalid_number" "login_denied" "no_data_found" "not_logged_on"
1164 "program_error" "rowtype_mismatch" "self_is_null" "storage_error"
1165 "subscript_beyond_count" "subscript_outside_limit" "sys_invalid_rowid"
1166 "timeout_on_resource" "too_many_rows" "value_error" "zero_divide"
1167 "exception" "notfound"
1170 (sqlplus-commands
1171 (eval-when-compile (concat "^\\(\\("
1172 (regexp-opt '(
1173 "@" "@@" "accept" "append" "archive" "attribute" "break"
1174 "btitle" "change" "clear" "column" "connect" "copy" "define"
1175 "del" "describe" "disconnect" "edit" "execute" "exit" "get" "help"
1176 "host" "input" "list" "password" "pause" "print" "prompt" "recover"
1177 "remark" "repfooter" "repheader" "run" "save" "show" "shutdown"
1178 "spool" "start" "startup" "store" "timing" "ttitle" "undefine"
1179 "variable" "whenever"
1181 ) t)
1183 "\\)\\|"
1184 "\\(compute\\s-+\\(avg\\|cou\\|min\\|max\\|num\\|sum\\|std\\|var\\)\\)\\|"
1185 "\\(set\\s-+\\(appi\\(nfo\\)?\\|array\\(size\\)?\\|"
1186 "auto\\(commit\\)?\\|autop\\(rint\\)?\\|autorecovery\\|"
1187 "autot\\(race\\)?\\|blo\\(ckterminator\\)?\\|cmds\\(ep\\)?\\|"
1188 "colsep\\|com\\(patibility\\)?\\|con\\(cat\\)?\\|"
1189 "copyc\\(ommit\\)?\\|copytypecheck\\|def\\(ine\\)?\\|"
1190 "describe\\|echo\\|editf\\(ile\\)?\\|emb\\(edded\\)?\\|"
1191 "esc\\(ape\\)?\\|feed\\(back\\)?\\|flagger\\|"
1192 "flu\\(sh\\)?\\|hea\\(ding\\)?\\|heads\\(ep\\)?\\|"
1193 "instance\\|lin\\(esize\\)?\\|lobof\\(fset\\)?\\|"
1194 "logsource\\|long\\|longc\\(hunksize\\)?\\|mark\\(up\\)?\\|"
1195 "newp\\(age\\)?\\|null\\|numf\\(ormat\\)?\\|"
1196 "num\\(width\\)?\\|pages\\(ize\\)?\\|pau\\(se\\)?\\|"
1197 "recsep\\|recsepchar\\|serverout\\(put\\)?\\|"
1198 "shift\\(inout\\)?\\|show\\(mode\\)?\\|"
1199 "sqlbl\\(anklines\\)?\\|sqlc\\(ase\\)?\\|"
1200 "sqlco\\(ntinue\\)?\\|sqln\\(umber\\)?\\|"
1201 "sqlpluscompat\\(ibility\\)?\\|sqlpre\\(fix\\)?\\|"
1202 "sqlp\\(rompt\\)?\\|sqlt\\(erminator\\)?\\|"
1203 "suf\\(fix\\)?\\|tab\\|term\\(out\\)?\\|ti\\(me\\)?\\|"
1204 "timi\\(ng\\)?\\|trim\\(out\\)?\\|trims\\(pool\\)?\\|"
1205 "und\\(erline\\)?\\|ver\\(ify\\)?\\|wra\\(p\\)?\\)\\)\\)"
1206 "\\b.*$"
1207 ))))
1209 `((,sqlplus-commands . font-lock-doc-face)
1210 (,oracle-functions . font-lock-builtin-face)
1211 (,oracle-keywords . font-lock-keyword-face)
1212 (,oracle-types . font-lock-type-face)
1213 (,plsql-functions . font-lock-builtin-face)
1214 (,plsql-keywords . font-lock-keyword-face)
1215 (,plsql-type . font-lock-type-face)
1216 (,plsql-warning . font-lock-warning-face)))
1218 "Oracle SQL keywords used by font-lock.
1220 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1221 regular expressions are created during compilation by calling the
1222 function `regexp-opt'. Therefore, take a look at the source before
1223 you define your own sql-mode-oracle-font-lock-keywords. You may want
1224 to add functions and PL/SQL keywords.")
1226 (defvar sql-mode-postgres-font-lock-keywords
1227 (let ((pg-funcs (sql-keywords-re
1228 "abbrev" "abs" "acos" "age" "area" "ascii" "asin" "atab2" "atan"
1229 "atan2" "avg" "bit_length" "both" "broadcast" "btrim" "cbrt" "ceil"
1230 "center" "char_length" "chr" "coalesce" "col_description" "convert"
1231 "cos" "cot" "count" "current_database" "current_date" "current_schema"
1232 "current_schemas" "current_setting" "current_time" "current_timestamp"
1233 "current_user" "currval" "date_part" "date_trunc" "decode" "degrees"
1234 "diameter" "encode" "exp" "extract" "floor" "get_bit" "get_byte"
1235 "has_database_privilege" "has_function_privilege"
1236 "has_language_privilege" "has_schema_privilege" "has_table_privilege"
1237 "height" "host" "initcap" "isclosed" "isfinite" "isopen" "leading"
1238 "length" "ln" "localtime" "localtimestamp" "log" "lower" "lpad"
1239 "ltrim" "masklen" "max" "min" "mod" "netmask" "network" "nextval"
1240 "now" "npoints" "nullif" "obj_description" "octet_length" "overlay"
1241 "pclose" "pg_client_encoding" "pg_function_is_visible"
1242 "pg_get_constraintdef" "pg_get_indexdef" "pg_get_ruledef"
1243 "pg_get_userbyid" "pg_get_viewdef" "pg_opclass_is_visible"
1244 "pg_operator_is_visible" "pg_table_is_visible" "pg_type_is_visible"
1245 "pi" "popen" "position" "pow" "quote_ident" "quote_literal" "radians"
1246 "radius" "random" "repeat" "replace" "round" "rpad" "rtrim"
1247 "session_user" "set_bit" "set_byte" "set_config" "set_masklen"
1248 "setval" "sign" "sin" "split_part" "sqrt" "stddev" "strpos" "substr"
1249 "substring" "sum" "tan" "timeofday" "to_ascii" "to_char" "to_date"
1250 "to_hex" "to_number" "to_timestamp" "trailing" "translate" "trim"
1251 "trunc" "upper" "variance" "version" "width"
1254 (pg-reserved (sql-keywords-re
1255 "abort" "access" "add" "after" "aggregate" "alignment" "all" "alter"
1256 "analyze" "and" "any" "as" "asc" "assignment" "authorization"
1257 "backward" "basetype" "before" "begin" "between" "binary" "by" "cache"
1258 "called" "cascade" "case" "cast" "characteristics" "check"
1259 "checkpoint" "class" "close" "cluster" "column" "comment" "commit"
1260 "committed" "commutator" "constraint" "constraints" "conversion"
1261 "copy" "create" "createdb" "createuser" "cursor" "cycle" "database"
1262 "deallocate" "declare" "default" "deferrable" "deferred" "definer"
1263 "delete" "delimiter" "desc" "distinct" "do" "domain" "drop" "each"
1264 "element" "else" "encoding" "encrypted" "end" "escape" "except"
1265 "exclusive" "execute" "exists" "explain" "extended" "external" "false"
1266 "fetch" "finalfunc" "for" "force" "foreign" "forward" "freeze" "from"
1267 "full" "function" "grant" "group" "gtcmp" "handler" "hashes" "having"
1268 "immediate" "immutable" "implicit" "in" "increment" "index" "inherits"
1269 "initcond" "initially" "input" "insensitive" "insert" "instead"
1270 "internallength" "intersect" "into" "invoker" "is" "isnull"
1271 "isolation" "join" "key" "language" "leftarg" "level" "like" "limit"
1272 "listen" "load" "local" "location" "lock" "ltcmp" "main" "match"
1273 "maxvalue" "merges" "minvalue" "mode" "move" "natural" "negator"
1274 "next" "nocreatedb" "nocreateuser" "none" "not" "nothing" "notify"
1275 "notnull" "null" "of" "offset" "oids" "on" "only" "operator" "or"
1276 "order" "output" "owner" "partial" "passedbyvalue" "password" "plain"
1277 "prepare" "primary" "prior" "privileges" "procedural" "procedure"
1278 "public" "read" "recheck" "references" "reindex" "relative" "rename"
1279 "reset" "restrict" "returns" "revoke" "rightarg" "rollback" "row"
1280 "rule" "schema" "scroll" "security" "select" "sequence" "serializable"
1281 "session" "set" "sfunc" "share" "show" "similar" "some" "sort1"
1282 "sort2" "stable" "start" "statement" "statistics" "storage" "strict"
1283 "stype" "sysid" "table" "temp" "template" "temporary" "then" "to"
1284 "transaction" "trigger" "true" "truncate" "trusted" "type"
1285 "unencrypted" "union" "unique" "unknown" "unlisten" "until" "update"
1286 "usage" "user" "using" "vacuum" "valid" "validator" "values"
1287 "variable" "verbose" "view" "volatile" "when" "where" "with" "without"
1288 "work"
1291 (pg-types (sql-keywords-re
1292 "anyarray" "bigint" "bigserial" "bit" "boolean" "box" "bytea" "char"
1293 "character" "cidr" "circle" "cstring" "date" "decimal" "double"
1294 "float4" "float8" "inet" "int2" "int4" "int8" "integer" "internal"
1295 "interval" "language_handler" "line" "lseg" "macaddr" "money"
1296 "numeric" "oid" "opaque" "path" "point" "polygon" "precision" "real"
1297 "record" "regclass" "regoper" "regoperator" "regproc" "regprocedure"
1298 "regtype" "serial" "serial4" "serial8" "smallint" "text" "time"
1299 "timestamp" "varchar" "varying" "void" "zone"
1302 `((,pg-funcs . font-lock-builtin-face)
1303 (,pg-reserved . font-lock-keyword-face)
1304 (,pg-types . font-lock-type-face)))
1306 "Postgres SQL keywords used by font-lock.
1308 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1309 regular expressions are created during compilation by calling the
1310 function `regexp-opt'. Therefore, take a look at the source before
1311 you define your own sql-mode-postgres-font-lock-keywords.")
1313 (defvar sql-mode-linter-font-lock-keywords
1314 (let ((linter-keywords (sql-keywords-re
1315 "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel"
1316 "committed" "count" "countblob" "cross" "current" "data" "database"
1317 "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred"
1318 "denied" "description" "device" "difference" "directory" "error"
1319 "escape" "euc" "exclusive" "external" "extfile" "false" "file"
1320 "filename" "filesize" "filetime" "filter" "findblob" "first" "foreign"
1321 "full" "fuzzy" "global" "granted" "ignore" "immediate" "increment"
1322 "indexes" "indexfile" "indexfiles" "indextime" "initial" "integrity"
1323 "internal" "key" "last_autoinc" "last_rowid" "limit" "linter"
1324 "linter_file_device" "linter_file_size" "linter_name_length" "ln"
1325 "local" "login" "maxisn" "maxrow" "maxrowid" "maxvalue" "message"
1326 "minvalue" "module" "names" "national" "natural" "new" "new_table"
1327 "no" "node" "noneuc" "nulliferror" "numbers" "off" "old" "old_table"
1328 "only" "operation" "optimistic" "option" "page" "partially" "password"
1329 "phrase" "plan" "precision" "primary" "priority" "privileges"
1330 "proc_info_size" "proc_par_name_len" "protocol" "quant" "range" "raw"
1331 "read" "record" "records" "references" "remote" "rename" "replication"
1332 "restart" "rewrite" "root" "row" "rule" "savepoint" "security"
1333 "sensitive" "sequence" "serializable" "server" "since" "size" "some"
1334 "startup" "statement" "station" "success" "sys_guid" "tables" "test"
1335 "timeout" "trace" "transaction" "translation" "trigger"
1336 "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown"
1337 "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes"
1338 "wait" "windows_code" "workspace" "write" "xml"
1341 (linter-reserved (sql-keywords-re
1342 "access" "action" "add" "address" "after" "all" "alter" "always" "and"
1343 "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit"
1344 "aud_obj_name_len" "backup" "base" "before" "between" "blobfile"
1345 "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check"
1346 "clear" "close" "column" "comment" "commit" "connect" "contains"
1347 "correct" "create" "delete" "desc" "disable" "disconnect" "distinct"
1348 "drop" "each" "ef" "else" "enable" "end" "event" "except" "exclude"
1349 "execute" "exists" "extract" "fetch" "finish" "for" "from" "get"
1350 "grant" "group" "having" "identified" "in" "index" "inner" "insert"
1351 "instead" "intersect" "into" "is" "isolation" "join" "left" "level"
1352 "like" "lock" "mode" "modify" "not" "nowait" "null" "of" "on" "open"
1353 "or" "order" "outer" "owner" "press" "prior" "procedure" "public"
1354 "purge" "rebuild" "resource" "restrict" "revoke" "right" "role"
1355 "rollback" "rownum" "select" "session" "set" "share" "shutdown"
1356 "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then"
1357 "to" "union" "unique" "unlock" "until" "update" "using" "values"
1358 "view" "when" "where" "with" "without"
1361 (linter-types (sql-keywords-re
1362 "bigint" "bitmap" "blob" "boolean" "char" "character" "date"
1363 "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar"
1364 "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte"
1365 "cursor" "long"
1368 (linter-functions (sql-keywords-re
1369 "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime"
1370 "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw"
1371 "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log"
1372 "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl"
1373 "octet_length" "power" "rand" "rawtohex" "repeat_string"
1374 "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex"
1375 "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date"
1376 "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode"
1377 "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap"
1378 "instr" "least" "multime" "replace" "width"
1381 `((,linter-keywords . font-lock-keyword-face)
1382 (,linter-reserved . font-lock-keyword-face)
1383 (,linter-functions . font-lock-builtin-face)
1384 (,linter-types . font-lock-type-face)))
1386 "Linter SQL keywords used by font-lock.
1388 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1389 regular expressions are created during compilation by calling the
1390 function `regexp-opt'.")
1392 (defvar sql-mode-ms-font-lock-keywords
1393 (let ((ms-reserved (sql-keywords-re
1394 "absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization"
1395 "avg" "backup" "begin" "between" "break" "browse" "bulk" "by"
1396 "cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce"
1397 "column" "commit" "committed" "compute" "confirm" "constraint"
1398 "contains" "containstable" "continue" "controlrow" "convert" "count"
1399 "create" "cross" "current" "current_date" "current_time"
1400 "current_timestamp" "current_user" "database" "deallocate" "declare"
1401 "default" "delete" "deny" "desc" "disk" "distinct" "distributed"
1402 "double" "drop" "dummy" "dump" "else" "end" "errlvl" "errorexit"
1403 "escape" "except" "exec" "execute" "exists" "exit" "fetch" "file"
1404 "fillfactor" "first" "floppy" "for" "foreign" "freetext"
1405 "freetexttable" "from" "full" "goto" "grant" "group" "having"
1406 "holdlock" "identity" "identity_insert" "identitycol" "if" "in"
1407 "index" "inner" "insert" "intersect" "into" "is" "isolation" "join"
1408 "key" "kill" "last" "left" "level" "like" "lineno" "load" "max" "min"
1409 "mirrorexit" "national" "next" "nocheck" "nolock" "nonclustered" "not"
1410 "null" "nullif" "of" "off" "offsets" "on" "once" "only" "open"
1411 "opendatasource" "openquery" "openrowset" "option" "or" "order"
1412 "outer" "output" "over" "paglock" "percent" "perm" "permanent" "pipe"
1413 "plan" "precision" "prepare" "primary" "print" "prior" "privileges"
1414 "proc" "procedure" "processexit" "public" "raiserror" "read"
1415 "readcommitted" "readpast" "readtext" "readuncommitted" "reconfigure"
1416 "references" "relative" "repeatable" "repeatableread" "replication"
1417 "restore" "restrict" "return" "revoke" "right" "rollback" "rowcount"
1418 "rowguidcol" "rowlock" "rule" "save" "schema" "select" "serializable"
1419 "session_user" "set" "shutdown" "some" "statistics" "sum"
1420 "system_user" "table" "tablock" "tablockx" "tape" "temp" "temporary"
1421 "textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate"
1422 "tsequal" "uncommitted" "union" "unique" "update" "updatetext"
1423 "updlock" "use" "user" "values" "view" "waitfor" "when" "where"
1424 "while" "with" "work" "writetext" "collate" "function" "openxml"
1425 "returns"
1428 (ms-types (sql-keywords-re
1429 "binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal"
1430 "double" "float" "image" "int" "integer" "money" "national" "nchar"
1431 "ntext" "numeric" "numeric" "nvarchar" "precision" "real"
1432 "smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint"
1433 "uniqueidentifier" "varbinary" "varchar" "varying"
1436 (ms-vars "\\b@[a-zA-Z0-9_]*\\b")
1438 (ms-functions (sql-keywords-re
1439 "@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts"
1440 "@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy"
1441 "@@langid" "@@language" "@@lock_timeout" "@@max_connections"
1442 "@@max_precision" "@@nestlevel" "@@options" "@@pack_received"
1443 "@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount"
1444 "@@servername" "@@servicename" "@@spid" "@@textsize" "@@timeticks"
1445 "@@total_errors" "@@total_read" "@@total_write" "@@trancount"
1446 "@@version" "abs" "acos" "and" "app_name" "ascii" "asin" "atan" "atn2"
1447 "avg" "case" "cast" "ceiling" "char" "charindex" "coalesce"
1448 "col_length" "col_name" "columnproperty" "containstable" "convert"
1449 "cos" "cot" "count" "current_timestamp" "current_user" "cursor_status"
1450 "databaseproperty" "datalength" "dateadd" "datediff" "datename"
1451 "datepart" "day" "db_id" "db_name" "degrees" "difference" "exp"
1452 "file_id" "file_name" "filegroup_id" "filegroup_name"
1453 "filegroupproperty" "fileproperty" "floor" "formatmessage"
1454 "freetexttable" "fulltextcatalogproperty" "fulltextserviceproperty"
1455 "getansinull" "getdate" "grouping" "host_id" "host_name" "ident_incr"
1456 "ident_seed" "identity" "index_col" "indexproperty" "is_member"
1457 "is_srvrolemember" "isdate" "isnull" "isnumeric" "left" "len" "log"
1458 "log10" "lower" "ltrim" "max" "min" "month" "nchar" "newid" "nullif"
1459 "object_id" "object_name" "objectproperty" "openquery" "openrowset"
1460 "parsename" "patindex" "patindex" "permissions" "pi" "power"
1461 "quotename" "radians" "rand" "replace" "replicate" "reverse" "right"
1462 "round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt"
1463 "square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum"
1464 "suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan"
1465 "textptr" "textvalid" "typeproperty" "unicode" "upper" "user"
1466 "user_id" "user_name" "var" "varp" "year"
1469 (ms-commands
1470 (eval-when-compile
1471 (concat "^\\(\\(set\\s-+\\("
1472 (regexp-opt '(
1473 "datefirst" "dateformat" "deadlock_priority" "lock_timeout"
1474 "concat_null_yields_null" "cursor_close_on_commit"
1475 "disable_def_cnst_chk" "fips_flagger" "identity_insert" "language"
1476 "offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly"
1477 "nocount" "noexec" "numeric_roundabort" "parseonly"
1478 "query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults"
1479 "ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding"
1480 "ansi_warnings" "forceplan" "showplan_all" "showplan_text"
1481 "statistics" "implicit_transactions" "remote_proc_transactions"
1482 "transaction" "xact_abort"
1483 ) t)
1484 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$"))))
1486 `((,ms-commands . font-lock-doc-face)
1487 (,ms-reserved . font-lock-keyword-face)
1488 (,ms-functions . font-lock-builtin-face)
1489 (,ms-vars . font-lock-variable-name-face)
1490 (,ms-types . font-lock-type-face)))
1492 "Microsoft SQLServer SQL keywords used by font-lock.
1494 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1495 regular expressions are created during compilation by calling the
1496 function `regexp-opt'. Therefore, take a look at the source before
1497 you define your own sql-mode-ms-font-lock-keywords.")
1499 (defvar sql-mode-sybase-font-lock-keywords nil
1500 "Sybase SQL keywords used by font-lock.
1502 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1503 regular expressions are created during compilation by calling the
1504 function `regexp-opt'. Therefore, take a look at the source before
1505 you define your own sql-mode-sybase-font-lock-keywords.")
1507 (defvar sql-mode-informix-font-lock-keywords nil
1508 "Informix SQL keywords used by font-lock.
1510 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1511 regular expressions are created during compilation by calling the
1512 function `regexp-opt'. Therefore, take a look at the source before
1513 you define your own sql-mode-informix-font-lock-keywords.")
1515 (defvar sql-mode-interbase-font-lock-keywords nil
1516 "Interbase SQL keywords used by font-lock.
1518 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1519 regular expressions are created during compilation by calling the
1520 function `regexp-opt'. Therefore, take a look at the source before
1521 you define your own sql-mode-interbase-font-lock-keywords.")
1523 (defvar sql-mode-ingres-font-lock-keywords nil
1524 "Ingres SQL keywords used by font-lock.
1526 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1527 regular expressions are created during compilation by calling the
1528 function `regexp-opt'. Therefore, take a look at the source before
1529 you define your own sql-mode-interbase-font-lock-keywords.")
1531 (defvar sql-mode-solid-font-lock-keywords nil
1532 "Solid SQL keywords used by font-lock.
1534 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1535 regular expressions are created during compilation by calling the
1536 function `regexp-opt'. Therefore, take a look at the source before
1537 you define your own sql-mode-solid-font-lock-keywords.")
1539 (defvar sql-mode-mysql-font-lock-keywords
1540 (let ((mysql-funcs (sql-keywords-re
1541 "ascii" "avg" "bdmpolyfromtext" "bdmpolyfromwkb" "bdpolyfromtext"
1542 "bdpolyfromwkb" "benchmark" "bin" "bit_and" "bit_length" "bit_or"
1543 "bit_xor" "both" "cast" "char_length" "character_length" "coalesce"
1544 "concat" "concat_ws" "connection_id" "conv" "convert" "count"
1545 "curdate" "current_date" "current_time" "current_timestamp" "curtime"
1546 "elt" "encrypt" "export_set" "field" "find_in_set" "found_rows" "from"
1547 "geomcollfromtext" "geomcollfromwkb" "geometrycollectionfromtext"
1548 "geometrycollectionfromwkb" "geometryfromtext" "geometryfromwkb"
1549 "geomfromtext" "geomfromwkb" "get_lock" "group_concat" "hex" "ifnull"
1550 "instr" "interval" "isnull" "last_insert_id" "lcase" "leading"
1551 "length" "linefromtext" "linefromwkb" "linestringfromtext"
1552 "linestringfromwkb" "load_file" "locate" "lower" "lpad" "ltrim"
1553 "make_set" "master_pos_wait" "max" "mid" "min" "mlinefromtext"
1554 "mlinefromwkb" "mpointfromtext" "mpointfromwkb" "mpolyfromtext"
1555 "mpolyfromwkb" "multilinestringfromtext" "multilinestringfromwkb"
1556 "multipointfromtext" "multipointfromwkb" "multipolygonfromtext"
1557 "multipolygonfromwkb" "now" "nullif" "oct" "octet_length" "ord"
1558 "pointfromtext" "pointfromwkb" "polyfromtext" "polyfromwkb"
1559 "polygonfromtext" "polygonfromwkb" "position" "quote" "rand"
1560 "release_lock" "repeat" "replace" "reverse" "rpad" "rtrim" "soundex"
1561 "space" "std" "stddev" "substring" "substring_index" "sum" "sysdate"
1562 "trailing" "trim" "ucase" "unix_timestamp" "upper" "user" "variance"
1565 (mysql-keywords (sql-keywords-re
1566 "action" "add" "after" "against" "all" "alter" "and" "as" "asc"
1567 "auto_increment" "avg_row_length" "bdb" "between" "by" "cascade"
1568 "case" "change" "character" "check" "checksum" "close" "collate"
1569 "collation" "column" "columns" "comment" "committed" "concurrent"
1570 "constraint" "create" "cross" "data" "database" "default"
1571 "delay_key_write" "delayed" "delete" "desc" "directory" "disable"
1572 "distinct" "distinctrow" "do" "drop" "dumpfile" "duplicate" "else"
1573 "enable" "enclosed" "end" "escaped" "exists" "fields" "first" "for"
1574 "force" "foreign" "from" "full" "fulltext" "global" "group" "handler"
1575 "having" "heap" "high_priority" "if" "ignore" "in" "index" "infile"
1576 "inner" "insert" "insert_method" "into" "is" "isam" "isolation" "join"
1577 "key" "keys" "last" "left" "level" "like" "limit" "lines" "load"
1578 "local" "lock" "low_priority" "match" "max_rows" "merge" "min_rows"
1579 "mode" "modify" "mrg_myisam" "myisam" "natural" "next" "no" "not"
1580 "null" "offset" "oj" "on" "open" "optionally" "or" "order" "outer"
1581 "outfile" "pack_keys" "partial" "password" "prev" "primary"
1582 "procedure" "quick" "raid0" "raid_type" "read" "references" "rename"
1583 "repeatable" "restrict" "right" "rollback" "rollup" "row_format"
1584 "savepoint" "select" "separator" "serializable" "session" "set"
1585 "share" "show" "sql_big_result" "sql_buffer_result" "sql_cache"
1586 "sql_calc_found_rows" "sql_no_cache" "sql_small_result" "starting"
1587 "straight_join" "striped" "table" "tables" "temporary" "terminated"
1588 "then" "to" "transaction" "truncate" "type" "uncommitted" "union"
1589 "unique" "unlock" "update" "use" "using" "values" "when" "where"
1590 "with" "write" "xor"
1593 (mysql-types (sql-keywords-re
1594 "bigint" "binary" "bit" "blob" "bool" "boolean" "char" "curve" "date"
1595 "datetime" "dec" "decimal" "double" "enum" "fixed" "float" "geometry"
1596 "geometrycollection" "int" "integer" "line" "linearring" "linestring"
1597 "longblob" "longtext" "mediumblob" "mediumint" "mediumtext"
1598 "multicurve" "multilinestring" "multipoint" "multipolygon"
1599 "multisurface" "national" "numeric" "point" "polygon" "precision"
1600 "real" "smallint" "surface" "text" "time" "timestamp" "tinyblob"
1601 "tinyint" "tinytext" "unsigned" "varchar" "year" "year2" "year4"
1602 "zerofill"
1605 `((,mysql-funcs . font-lock-builtin-face)
1606 (,mysql-keywords . font-lock-keyword-face)
1607 (,mysql-types . font-lock-type-face)))
1609 "MySQL SQL keywords used by font-lock.
1611 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1612 regular expressions are created during compilation by calling the
1613 function `regexp-opt'. Therefore, take a look at the source before
1614 you define your own sql-mode-mysql-font-lock-keywords.")
1616 (defvar sql-mode-sqlite-font-lock-keywords nil
1617 "SQLite SQL keywords used by font-lock.
1619 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1620 regular expressions are created during compilation by calling the
1621 function `regexp-opt'. Therefore, take a look at the source before
1622 you define your own sql-mode-sqlite-font-lock-keywords.")
1624 (defvar sql-mode-db2-font-lock-keywords nil
1625 "DB2 SQL keywords used by font-lock.
1627 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1628 regular expressions are created during compilation by calling the
1629 function `regexp-opt'. Therefore, take a look at the source before
1630 you define your own sql-mode-db2-font-lock-keywords.")
1632 (defvar sql-mode-font-lock-keywords nil
1633 "SQL keywords used by font-lock.
1635 Setting this variable directly no longer has any affect. Use
1636 `sql-product' and `sql-add-product-keywords' to control the
1637 highlighting rules in sql-mode.")
1641 ;;; SQL Product support functions
1643 (defun sql-product-feature (feature &optional product)
1644 "Lookup `feature' needed to support the current SQL product.
1646 See \[sql-product-alist] for a list of products and supported features."
1647 (plist-get
1648 (cdr (assoc (or product sql-product)
1649 sql-product-alist))
1650 feature))
1652 (defun sql-product-font-lock (keywords-only imenu)
1653 "Sets `font-lock-defaults' and `font-lock-keywords' based on
1654 the product-specific keywords and syntax-alists defined in
1655 `sql-product-alist'."
1656 (let
1657 ;; Get the product-specific syntax-alist.
1658 ((syntax-alist
1659 (append
1660 (sql-product-feature :syntax-alist)
1661 '((?_ . "w") (?. . "w")))))
1663 ;; Get the product-specific keywords.
1664 (setq sql-mode-font-lock-keywords
1665 (append
1666 (unless (eq sql-product 'ansi)
1667 (eval (sql-product-feature :font-lock)))
1668 ;; Always highlight ANSI keywords
1669 (eval (sql-product-feature :font-lock 'ansi))
1670 ;; Fontify object names in CREATE, DROP and ALTER DDL
1671 ;; statements
1672 (list sql-mode-font-lock-object-name)))
1674 ;; Setup font-lock. Force re-parsing of `font-lock-defaults'.
1675 (set (make-local-variable 'font-lock-set-defaults) nil)
1676 (setq font-lock-defaults (list 'sql-mode-font-lock-keywords
1677 keywords-only t syntax-alist))
1679 ;; Force font lock to reinitialize if it is already on
1680 ;; Otherwise, we can wait until it can be started.
1681 (when (and (fboundp 'font-lock-mode)
1682 font-lock-mode)
1683 (font-lock-mode-internal nil)
1684 (font-lock-mode-internal t))
1686 (add-hook 'font-lock-mode-hook
1687 (lambda ()
1688 ;; Provide defaults for new font-lock faces.
1689 (defvar font-lock-builtin-face
1690 (if (boundp 'font-lock-preprocessor-face)
1691 font-lock-preprocessor-face
1692 font-lock-keyword-face))
1693 (defvar font-lock-doc-face font-lock-string-face))
1694 nil t)
1696 ;; Setup imenu; it needs the same syntax-alist.
1697 (when imenu
1698 (setq imenu-syntax-alist syntax-alist))))
1700 ;;;###autoload
1701 (defun sql-add-product-keywords (product keywords &optional append)
1702 "Add highlighting KEYWORDS for SQL PRODUCT.
1704 PRODUCT should be a symbol, the name of a sql product, such as
1705 `oracle'. KEYWORDS should be a list; see the variable
1706 `font-lock-keywords'. By default they are added at the beginning
1707 of the current highlighting list. If optional argument APPEND is
1708 `set', they are used to replace the current highlighting list.
1709 If APPEND is any other non-nil value, they are added at the end
1710 of the current highlighting list.
1712 For example:
1714 (sql-add-product-keywords 'ms
1715 '((\"\\\\b\\\\w+_t\\\\b\" . font-lock-type-face)))
1717 adds a fontification pattern to fontify identifiers ending in
1718 `_t' as data types."
1720 (let ((font-lock (sql-product-feature :font-lock product))
1721 old)
1722 (setq old (eval font-lock))
1723 (set font-lock
1724 (if (eq append 'set)
1725 keywords
1726 (if append
1727 (append old keywords)
1728 (append keywords old))))))
1732 ;;; Functions to switch highlighting
1734 (defun sql-highlight-product ()
1735 "Turns on the appropriate font highlighting for the SQL product
1736 selected."
1738 (when (eq major-mode 'sql-mode)
1739 ;; Setup font-lock
1740 (sql-product-font-lock nil t)
1742 ;; Set the mode name to include the product.
1743 (setq mode-name (concat "SQL[" (prin1-to-string sql-product) "]"))))
1745 (defun sql-set-product (product)
1746 "Set `sql-product' to product and enable appropriate
1747 highlighting."
1748 (interactive "SEnter SQL product: ")
1749 (when (not (assoc product sql-product-alist))
1750 (error "SQL product %s is not supported; treated as ANSI" product)
1751 (setq product 'ansi))
1753 ;; Save product setting and fontify.
1754 (setq sql-product product)
1755 (sql-highlight-product))
1757 (defun sql-highlight-oracle-keywords ()
1758 "Highlight Oracle keywords."
1759 (interactive)
1760 (sql-set-product 'oracle))
1762 (defun sql-highlight-postgres-keywords ()
1763 "Highlight Postgres keywords."
1764 (interactive)
1765 (sql-set-product 'postgres))
1767 (defun sql-highlight-linter-keywords ()
1768 "Highlight LINTER keywords."
1769 (interactive)
1770 (sql-set-product 'linter))
1772 (defun sql-highlight-ms-keywords ()
1773 "Highlight Microsoft SQLServer keywords."
1774 (interactive)
1775 (sql-set-product 'ms))
1777 (defun sql-highlight-ansi-keywords ()
1778 "Highlight ANSI SQL keywords."
1779 (interactive)
1780 (sql-set-product 'ansi))
1782 (defun sql-highlight-sybase-keywords ()
1783 "Highlight Sybase SQL keywords."
1784 (interactive)
1785 (sql-set-product 'sybase))
1787 (defun sql-highlight-informix-keywords ()
1788 "Highlight Informix SQL keywords."
1789 (interactive)
1790 (sql-set-product 'informix))
1792 (defun sql-highlight-interbase-keywords ()
1793 "Highlight Interbase SQL keywords."
1794 (interactive)
1795 (sql-set-product 'interbase))
1797 (defun sql-highlight-ingres-keywords ()
1798 "Highlight Ingres SQL keywords."
1799 (interactive)
1800 (sql-set-product 'ingres))
1802 (defun sql-highlight-solid-keywords ()
1803 "Highlight Solid SQL keywords."
1804 (interactive)
1805 (sql-set-product 'solid))
1807 (defun sql-highlight-mysql-keywords ()
1808 "Highlight MySQL SQL keywords."
1809 (interactive)
1810 (sql-set-product 'mysql))
1812 (defun sql-highlight-sqlite-keywords ()
1813 "Highlight SQLite SQL keywords."
1814 (interactive)
1815 (sql-set-product 'sqlite))
1817 (defun sql-highlight-db2-keywords ()
1818 "Highlight DB2 SQL keywords."
1819 (interactive)
1820 (sql-set-product 'db2))
1824 ;;; Compatibility functions
1826 (if (not (fboundp 'comint-line-beginning-position))
1827 ;; comint-line-beginning-position is defined in Emacs 21
1828 (defun comint-line-beginning-position ()
1829 "Returns the buffer position of the beginning of the line, after any prompt.
1830 The prompt is assumed to be any text at the beginning of the line matching
1831 the regular expression `comint-prompt-regexp', a buffer local variable."
1832 (save-excursion (comint-bol nil) (point))))
1836 ;;; Small functions
1838 (defun sql-magic-go (arg)
1839 "Insert \"o\" and call `comint-send-input'.
1840 `sql-electric-stuff' must be the symbol `go'."
1841 (interactive "P")
1842 (self-insert-command (prefix-numeric-value arg))
1843 (if (and (equal sql-electric-stuff 'go)
1844 (save-excursion
1845 (comint-bol nil)
1846 (looking-at "go\\b")))
1847 (comint-send-input)))
1849 (defun sql-magic-semicolon (arg)
1850 "Insert semicolon and call `comint-send-input'.
1851 `sql-electric-stuff' must be the symbol `semicolon'."
1852 (interactive "P")
1853 (self-insert-command (prefix-numeric-value arg))
1854 (if (equal sql-electric-stuff 'semicolon)
1855 (comint-send-input)))
1857 (defun sql-accumulate-and-indent ()
1858 "Continue SQL statement on the next line."
1859 (interactive)
1860 (if (fboundp 'comint-accumulate)
1861 (comint-accumulate)
1862 (newline))
1863 (indent-according-to-mode))
1865 ;;;###autoload
1866 (defun sql-help ()
1867 "Show short help for the SQL modes.
1869 Use an entry function to open an interactive SQL buffer. This buffer is
1870 usually named `*SQL*'. The name of the major mode is SQLi.
1872 Use the following commands to start a specific SQL interpreter:
1874 PostGres: \\[sql-postgres]
1875 MySQL: \\[sql-mysql]
1876 SQLite: \\[sql-sqlite]
1878 Other non-free SQL implementations are also supported:
1880 Solid: \\[sql-solid]
1881 Oracle: \\[sql-oracle]
1882 Informix: \\[sql-informix]
1883 Sybase: \\[sql-sybase]
1884 Ingres: \\[sql-ingres]
1885 Microsoft: \\[sql-ms]
1886 DB2: \\[sql-db2]
1887 Interbase: \\[sql-interbase]
1888 Linter: \\[sql-linter]
1890 But we urge you to choose a free implementation instead of these.
1892 Once you have the SQLi buffer, you can enter SQL statements in the
1893 buffer. The output generated is appended to the buffer and a new prompt
1894 is generated. See the In/Out menu in the SQLi buffer for some functions
1895 that help you navigate through the buffer, the input history, etc.
1897 If you have a really complex SQL statement or if you are writing a
1898 procedure, you can do this in a separate buffer. Put the new buffer in
1899 `sql-mode' by calling \\[sql-mode]. The name of this buffer can be
1900 anything. The name of the major mode is SQL.
1902 In this SQL buffer (SQL mode), you can send the region or the entire
1903 buffer to the interactive SQL buffer (SQLi mode). The results are
1904 appended to the SQLi buffer without disturbing your SQL buffer."
1905 (interactive)
1906 (describe-function 'sql-help))
1908 (defun sql-read-passwd (prompt &optional default)
1909 "Read a password using PROMPT. Optional DEFAULT is password to start with."
1910 (read-passwd prompt nil default))
1912 (defun sql-get-login (&rest what)
1913 "Get username, password and database from the user.
1915 The variables `sql-user', `sql-password', `sql-server', and
1916 `sql-database' can be customized. They are used as the default values.
1917 Usernames, servers and databases are stored in `sql-user-history',
1918 `sql-server-history' and `database-history'. Passwords are not stored
1919 in a history.
1921 Parameter WHAT is a list of the arguments passed to this function.
1922 The function asks for the username if WHAT contains symbol `user', for
1923 the password if it contains symbol `password', for the server if it
1924 contains symbol `server', and for the database if it contains symbol
1925 `database'. The members of WHAT are processed in the order in which
1926 they are provided.
1928 In order to ask the user for username, password and database, call the
1929 function like this: (sql-get-login 'user 'password 'database)."
1930 (interactive)
1931 (while what
1932 (cond
1933 ((eq (car what) 'user) ; user
1934 (setq sql-user
1935 (read-from-minibuffer "User: " sql-user nil nil
1936 sql-user-history)))
1937 ((eq (car what) 'password) ; password
1938 (setq sql-password
1939 (sql-read-passwd "Password: " sql-password)))
1940 ((eq (car what) 'server) ; server
1941 (setq sql-server
1942 (read-from-minibuffer "Server: " sql-server nil nil
1943 sql-server-history)))
1944 ((eq (car what) 'database) ; database
1945 (setq sql-database
1946 (read-from-minibuffer "Database: " sql-database nil nil
1947 sql-database-history))))
1948 (setq what (cdr what))))
1950 (defun sql-find-sqli-buffer ()
1951 "Return the current default SQLi buffer or nil.
1952 In order to qualify, the SQLi buffer must be alive,
1953 be in `sql-interactive-mode' and have a process."
1954 (let ((default-buffer (default-value 'sql-buffer)))
1955 (if (and (buffer-live-p default-buffer)
1956 (get-buffer-process default-buffer))
1957 default-buffer
1958 (save-excursion
1959 (let ((buflist (buffer-list))
1960 (found))
1961 (while (not (or (null buflist)
1962 found))
1963 (let ((candidate (car buflist)))
1964 (set-buffer candidate)
1965 (if (and (equal major-mode 'sql-interactive-mode)
1966 (get-buffer-process candidate))
1967 (setq found candidate))
1968 (setq buflist (cdr buflist))))
1969 found)))))
1971 (defun sql-set-sqli-buffer-generally ()
1972 "Set SQLi buffer for all SQL buffers that have none.
1973 This function checks all SQL buffers for their SQLi buffer. If their
1974 SQLi buffer is nonexistent or has no process, it is set to the current
1975 default SQLi buffer. The current default SQLi buffer is determined
1976 using `sql-find-sqli-buffer'. If `sql-buffer' is set,
1977 `sql-set-sqli-hook' is run."
1978 (interactive)
1979 (save-excursion
1980 (let ((buflist (buffer-list))
1981 (default-sqli-buffer (sql-find-sqli-buffer)))
1982 (setq-default sql-buffer default-sqli-buffer)
1983 (while (not (null buflist))
1984 (let ((candidate (car buflist)))
1985 (set-buffer candidate)
1986 (if (and (equal major-mode 'sql-mode)
1987 (not (buffer-live-p sql-buffer)))
1988 (progn
1989 (setq sql-buffer default-sqli-buffer)
1990 (run-hooks 'sql-set-sqli-hook))))
1991 (setq buflist (cdr buflist))))))
1993 (defun sql-set-sqli-buffer ()
1994 "Set the SQLi buffer SQL strings are sent to.
1996 Call this function in a SQL buffer in order to set the SQLi buffer SQL
1997 strings are sent to. Calling this function sets `sql-buffer' and runs
1998 `sql-set-sqli-hook'.
2000 If you call it from a SQL buffer, this sets the local copy of
2001 `sql-buffer'.
2003 If you call it from anywhere else, it sets the global copy of
2004 `sql-buffer'."
2005 (interactive)
2006 (let ((default-buffer (sql-find-sqli-buffer)))
2007 (if (null default-buffer)
2008 (error "There is no suitable SQLi buffer"))
2009 (let ((new-buffer
2010 (get-buffer
2011 (read-buffer "New SQLi buffer: " default-buffer t))))
2012 (if (null (get-buffer-process new-buffer))
2013 (error "Buffer %s has no process" (buffer-name new-buffer)))
2014 (if (null (save-excursion
2015 (set-buffer new-buffer)
2016 (equal major-mode 'sql-interactive-mode)))
2017 (error "Buffer %s is no SQLi buffer" (buffer-name new-buffer)))
2018 (if new-buffer
2019 (progn
2020 (setq sql-buffer new-buffer)
2021 (run-hooks 'sql-set-sqli-hook))))))
2023 (defun sql-show-sqli-buffer ()
2024 "Show the name of current SQLi buffer.
2026 This is the buffer SQL strings are sent to. It is stored in the
2027 variable `sql-buffer'. See `sql-help' on how to create such a buffer."
2028 (interactive)
2029 (if (null (buffer-live-p sql-buffer))
2030 (message "%s has no SQLi buffer set." (buffer-name (current-buffer)))
2031 (if (null (get-buffer-process sql-buffer))
2032 (message "Buffer %s has no process." (buffer-name sql-buffer))
2033 (message "Current SQLi buffer is %s." (buffer-name sql-buffer)))))
2035 (defun sql-make-alternate-buffer-name ()
2036 "Return a string that can be used to rename a SQLi buffer.
2038 This is used to set `sql-alternate-buffer-name' within
2039 `sql-interactive-mode'."
2040 (concat (if (string= "" sql-user)
2041 (if (string= "" (user-login-name))
2043 (concat (user-login-name) "/"))
2044 (concat sql-user "/"))
2045 (if (string= "" sql-database)
2046 (if (string= "" sql-server)
2047 (system-name)
2048 sql-server)
2049 sql-database)))
2051 (defun sql-rename-buffer ()
2052 "Renames a SQLi buffer."
2053 (interactive)
2054 (rename-buffer (format "*SQL: %s*" sql-alternate-buffer-name) t))
2056 (defun sql-copy-column ()
2057 "Copy current column to the end of buffer.
2058 Inserts SELECT or commas if appropriate."
2059 (interactive)
2060 (let ((column))
2061 (save-excursion
2062 (setq column (buffer-substring
2063 (progn (forward-char 1) (backward-sexp 1) (point))
2064 (progn (forward-sexp 1) (point))))
2065 (goto-char (point-max))
2066 (let ((bol (comint-line-beginning-position)))
2067 (cond
2068 ;; if empty command line, insert SELECT
2069 ((= bol (point))
2070 (insert "SELECT "))
2071 ;; else if appending to INTO .* (, SELECT or ORDER BY, insert a comma
2072 ((save-excursion
2073 (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+"
2074 bol t))
2075 (insert ", "))
2076 ;; else insert a space
2078 (if (eq (preceding-char) ?\s)
2080 (insert " ")))))
2081 ;; in any case, insert the column
2082 (insert column)
2083 (message "%s" column))))
2085 ;; On NT, SQL*Plus for Oracle turns on full buffering for stdout if it
2086 ;; is not attached to a character device; therefore placeholder
2087 ;; replacement by SQL*Plus is fully buffered. The workaround lets
2088 ;; Emacs query for the placeholders.
2090 (defvar sql-placeholder-history nil
2091 "History of placeholder values used.")
2093 (defun sql-query-placeholders-and-send (proc string)
2094 "Send to PROC input STRING, maybe replacing placeholders.
2095 Placeholders are words starting with and ampersand like &this.
2096 This function is used for `comint-input-sender' if using `sql-oracle' on NT."
2097 (while (string-match "&\\(\\sw+\\)" string)
2098 (setq string (replace-match
2099 (read-from-minibuffer
2100 (format "Enter value for %s: " (match-string 1 string))
2101 nil nil nil sql-placeholder-history)
2102 t t string)))
2103 (comint-send-string proc string)
2104 (if comint-input-sender-no-newline
2105 (if (not (string-equal string ""))
2106 (process-send-eof))
2107 (comint-send-string proc "\n")))
2109 ;; Using DB2 interactively, newlines must be escaped with " \".
2110 ;; The space before the backslash is relevant.
2111 (defun sql-escape-newlines-and-send (proc string)
2112 "Send to PROC input STRING, escaping newlines if necessary.
2113 Every newline in STRING will be preceded with a space and a backslash."
2114 (let ((result "") (start 0) mb me)
2115 (while (string-match "\n" string start)
2116 (setq mb (match-beginning 0)
2117 me (match-end 0))
2118 (if (and (> mb 1)
2119 (string-equal " \\" (substring string (- mb 2) mb)))
2120 (setq result (concat result (substring string start me)))
2121 (setq result (concat result (substring string start mb) " \\\n")))
2122 (setq start me))
2123 (setq result (concat result (substring string start)))
2124 (comint-send-string proc result)
2125 (if comint-input-sender-no-newline
2126 (if (not (string-equal string ""))
2127 (process-send-eof))
2128 (comint-send-string proc "\n"))))
2132 ;;; Sending the region to the SQLi buffer.
2134 (defun sql-send-region (start end)
2135 "Send a region to the SQL process."
2136 (interactive "r")
2137 (if (buffer-live-p sql-buffer)
2138 (save-excursion
2139 (comint-send-region sql-buffer start end)
2140 (if (string-match "\n$" (buffer-substring start end))
2142 (comint-send-string sql-buffer "\n"))
2143 (message "Sent string to buffer %s." (buffer-name sql-buffer))
2144 (if sql-pop-to-buffer-after-send-region
2145 (pop-to-buffer sql-buffer)
2146 (display-buffer sql-buffer)))
2147 (message "No SQL process started.")))
2149 (defun sql-send-paragraph ()
2150 "Send the current paragraph to the SQL process."
2151 (interactive)
2152 (let ((start (save-excursion
2153 (backward-paragraph)
2154 (point)))
2155 (end (save-excursion
2156 (forward-paragraph)
2157 (point))))
2158 (sql-send-region start end)))
2160 (defun sql-send-buffer ()
2161 "Send the buffer contents to the SQL process."
2162 (interactive)
2163 (sql-send-region (point-min) (point-max)))
2165 (defun sql-send-string (str)
2166 "Send a string to the SQL process."
2167 (interactive "sSQL Text: ")
2168 (if (buffer-live-p sql-buffer)
2169 (save-excursion
2170 (comint-send-string sql-buffer str)
2171 (comint-send-string sql-buffer "\n")
2172 (message "Sent string to buffer %s." (buffer-name sql-buffer))
2173 (if sql-pop-to-buffer-after-send-region
2174 (pop-to-buffer sql-buffer)
2175 (display-buffer sql-buffer)))
2176 (message "No SQL process started.")))
2178 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value)
2179 "Toggle `sql-pop-to-buffer-after-send-region'.
2181 If given the optional parameter VALUE, sets
2182 sql-toggle-pop-to-buffer-after-send-region to VALUE."
2183 (interactive "P")
2184 (if value
2185 (setq sql-pop-to-buffer-after-send-region value)
2186 (setq sql-pop-to-buffer-after-send-region
2187 (null sql-pop-to-buffer-after-send-region ))))
2191 ;;; SQL mode -- uses SQL interactive mode
2193 ;;;###autoload
2194 (defun sql-mode ()
2195 "Major mode to edit SQL.
2197 You can send SQL statements to the SQLi buffer using
2198 \\[sql-send-region]. Such a buffer must exist before you can do this.
2199 See `sql-help' on how to create SQLi buffers.
2201 \\{sql-mode-map}
2202 Customization: Entry to this mode runs the `sql-mode-hook'.
2204 When you put a buffer in SQL mode, the buffer stores the last SQLi
2205 buffer created as its destination in the variable `sql-buffer'. This
2206 will be the buffer \\[sql-send-region] sends the region to. If this
2207 SQLi buffer is killed, \\[sql-send-region] is no longer able to
2208 determine where the strings should be sent to. You can set the
2209 value of `sql-buffer' using \\[sql-set-sqli-buffer].
2211 For information on how to create multiple SQLi buffers, see
2212 `sql-interactive-mode'.
2214 Note that SQL doesn't have an escape character unless you specify
2215 one. If you specify backslash as escape character in SQL,
2216 you must tell Emacs. Here's how to do that in your `~/.emacs' file:
2218 \(add-hook 'sql-mode-hook
2219 (lambda ()
2220 (modify-syntax-entry ?\\\\ \".\" sql-mode-syntax-table)))"
2221 (interactive)
2222 (kill-all-local-variables)
2223 (setq major-mode 'sql-mode)
2224 (setq mode-name "SQL")
2225 (use-local-map sql-mode-map)
2226 (if sql-mode-menu
2227 (easy-menu-add sql-mode-menu)); XEmacs
2228 (set-syntax-table sql-mode-syntax-table)
2229 (make-local-variable 'font-lock-defaults)
2230 (make-local-variable 'sql-mode-font-lock-keywords)
2231 (make-local-variable 'comment-start)
2232 (setq comment-start "--")
2233 ;; Make each buffer in sql-mode remember the "current" SQLi buffer.
2234 (make-local-variable 'sql-buffer)
2235 ;; Add imenu support for sql-mode. Note that imenu-generic-expression
2236 ;; is buffer-local, so we don't need a local-variable for it. SQL is
2237 ;; case-insensitive, that's why we have to set imenu-case-fold-search.
2238 (setq imenu-generic-expression sql-imenu-generic-expression
2239 imenu-case-fold-search t)
2240 ;; Make `sql-send-paragraph' work on paragraphs that contain indented
2241 ;; lines.
2242 (make-local-variable 'paragraph-separate)
2243 (make-local-variable 'paragraph-start)
2244 (setq paragraph-separate "[\f]*$"
2245 paragraph-start "[\n\f]")
2246 ;; Abbrevs
2247 (setq local-abbrev-table sql-mode-abbrev-table)
2248 (setq abbrev-all-caps 1)
2249 ;; Run hook
2250 (run-mode-hooks 'sql-mode-hook)
2251 ;; Catch changes to sql-product and highlight accordingly
2252 (sql-highlight-product)
2253 (add-hook 'hack-local-variables-hook 'sql-highlight-product t t))
2257 ;;; SQL interactive mode
2259 (put 'sql-interactive-mode 'mode-class 'special)
2261 (defun sql-interactive-mode ()
2262 "Major mode to use a SQL interpreter interactively.
2264 Do not call this function by yourself. The environment must be
2265 initialized by an entry function specific for the SQL interpreter. See
2266 `sql-help' for a list of available entry functions.
2268 \\[comint-send-input] after the end of the process' output sends the
2269 text from the end of process to the end of the current line.
2270 \\[comint-send-input] before end of process output copies the current
2271 line minus the prompt to the end of the buffer and sends it.
2272 \\[comint-copy-old-input] just copies the current line.
2273 Use \\[sql-accumulate-and-indent] to enter multi-line statements.
2275 If you want to make multiple SQL buffers, rename the `*SQL*' buffer
2276 using \\[rename-buffer] or \\[rename-uniquely] and start a new process.
2277 See `sql-help' for a list of available entry functions. The last buffer
2278 created by such an entry function is the current SQLi buffer. SQL
2279 buffers will send strings to the SQLi buffer current at the time of
2280 their creation. See `sql-mode' for details.
2282 Sample session using two connections:
2284 1. Create first SQLi buffer by calling an entry function.
2285 2. Rename buffer \"*SQL*\" to \"*Connection 1*\".
2286 3. Create a SQL buffer \"test1.sql\".
2287 4. Create second SQLi buffer by calling an entry function.
2288 5. Rename buffer \"*SQL*\" to \"*Connection 2*\".
2289 6. Create a SQL buffer \"test2.sql\".
2291 Now \\[sql-send-region] in buffer \"test1.sql\" will send the region to
2292 buffer \"*Connection 1*\", \\[sql-send-region] in buffer \"test2.sql\"
2293 will send the region to buffer \"*Connection 2*\".
2295 If you accidentally suspend your process, use \\[comint-continue-subjob]
2296 to continue it. On some operating systems, this will not work because
2297 the signals are not supported.
2299 \\{sql-interactive-mode-map}
2300 Customization: Entry to this mode runs the hooks on `comint-mode-hook'
2301 and `sql-interactive-mode-hook' (in that order). Before each input, the
2302 hooks on `comint-input-filter-functions' are run. After each SQL
2303 interpreter output, the hooks on `comint-output-filter-functions' are
2304 run.
2306 Variable `sql-input-ring-file-name' controls the initialization of the
2307 input ring history.
2309 Variables `comint-output-filter-functions', a hook, and
2310 `comint-scroll-to-bottom-on-input' and
2311 `comint-scroll-to-bottom-on-output' control whether input and output
2312 cause the window to scroll to the end of the buffer.
2314 If you want to make SQL buffers limited in length, add the function
2315 `comint-truncate-buffer' to `comint-output-filter-functions'.
2317 Here is an example for your .emacs file. It keeps the SQLi buffer a
2318 certain length.
2320 \(add-hook 'sql-interactive-mode-hook
2321 \(function (lambda ()
2322 \(setq comint-output-filter-functions 'comint-truncate-buffer))))
2324 Here is another example. It will always put point back to the statement
2325 you entered, right above the output it created.
2327 \(setq comint-output-filter-functions
2328 \(function (lambda (STR) (comint-show-output))))"
2329 (delay-mode-hooks (comint-mode))
2330 ;; Get the `sql-product' for this interactive session.
2331 (set (make-local-variable 'sql-product)
2332 (or sql-interactive-product
2333 sql-product))
2334 ;; Setup the mode.
2335 (setq major-mode 'sql-interactive-mode)
2336 (setq mode-name (concat "SQLi[" (prin1-to-string sql-product) "]"))
2337 (use-local-map sql-interactive-mode-map)
2338 (if sql-interactive-mode-menu
2339 (easy-menu-add sql-interactive-mode-menu)) ; XEmacs
2340 (set-syntax-table sql-mode-syntax-table)
2341 (make-local-variable 'sql-mode-font-lock-keywords)
2342 (make-local-variable 'font-lock-defaults)
2343 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
2344 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
2345 ;; will have just one quote. Therefore syntactic hilighting is
2346 ;; disabled for interactive buffers. No imenu support.
2347 (sql-product-font-lock t nil)
2348 ;; Enable commenting and uncommenting of the region.
2349 (make-local-variable 'comment-start)
2350 (setq comment-start "--")
2351 ;; Abbreviation table init and case-insensitive. It is not activated
2352 ;; by default.
2353 (setq local-abbrev-table sql-mode-abbrev-table)
2354 (setq abbrev-all-caps 1)
2355 ;; Exiting the process will call sql-stop.
2356 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop)
2357 ;; Create a usefull name for renaming this buffer later.
2358 (make-local-variable 'sql-alternate-buffer-name)
2359 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name))
2360 ;; User stuff. Initialize before the hook.
2361 (set (make-local-variable 'sql-prompt-regexp)
2362 (sql-product-feature :sqli-prompt-regexp))
2363 (set (make-local-variable 'sql-prompt-length)
2364 (sql-product-feature :sqli-prompt-length))
2365 (make-local-variable 'sql-input-ring-separator)
2366 (make-local-variable 'sql-input-ring-file-name)
2367 ;; Run hook.
2368 (run-mode-hooks 'sql-interactive-mode-hook)
2369 ;; Set comint based on user overrides.
2370 (setq comint-prompt-regexp sql-prompt-regexp)
2371 (setq left-margin sql-prompt-length)
2372 ;; People wanting a different history file for each
2373 ;; buffer/process/client/whatever can change separator and file-name
2374 ;; on the sql-interactive-mode-hook.
2375 (setq comint-input-ring-separator sql-input-ring-separator
2376 comint-input-ring-file-name sql-input-ring-file-name)
2377 ;; Calling the hook before calling comint-read-input-ring allows users
2378 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook.
2379 (comint-read-input-ring t))
2381 (defun sql-stop (process event)
2382 "Called when the SQL process is stopped.
2384 Writes the input history to a history file using
2385 `comint-write-input-ring' and inserts a short message in the SQL buffer.
2387 This function is a sentinel watching the SQL interpreter process.
2388 Sentinels will always get the two parameters PROCESS and EVENT."
2389 (comint-write-input-ring)
2390 (if (and (eq (current-buffer) sql-buffer)
2391 (not buffer-read-only))
2392 (insert (format "\nProcess %s %s\n" process event))
2393 (message "Process %s %s" process event)))
2397 ;;; Entry functions for different SQL interpreters.
2399 ;;;###autoload
2400 (defun sql-product-interactive (&optional product)
2401 "Run product interpreter as an inferior process.
2403 If buffer `*SQL*' exists but no process is running, make a new process.
2404 If buffer exists and a process is running, just switch to buffer
2405 `*SQL*'.
2407 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2408 (interactive)
2409 (setq product (or product sql-product))
2410 (when (sql-product-feature :sqli-connect product)
2411 (if (comint-check-proc "*SQL*")
2412 (pop-to-buffer "*SQL*")
2413 ;; Get credentials.
2414 (apply 'sql-get-login (sql-product-feature :sqli-login product))
2415 ;; Connect to database.
2416 (message "Login...")
2417 (funcall (sql-product-feature :sqli-connect product))
2418 ;; Set SQLi mode.
2419 (setq sql-interactive-product product)
2420 (setq sql-buffer (current-buffer))
2421 (sql-interactive-mode)
2422 ;; All done.
2423 (message "Login...done")
2424 (pop-to-buffer sql-buffer))))
2426 ;;;###autoload
2427 (defun sql-oracle ()
2428 "Run sqlplus by Oracle as an inferior process.
2430 If buffer `*SQL*' exists but no process is running, make a new process.
2431 If buffer exists and a process is running, just switch to buffer
2432 `*SQL*'.
2434 Interpreter used comes from variable `sql-oracle-program'. Login uses
2435 the variables `sql-user', `sql-password', and `sql-database' as
2436 defaults, if set. Additional command line parameters can be stored in
2437 the list `sql-oracle-options'.
2439 The buffer is put in sql-interactive-mode, giving commands for sending
2440 input. See `sql-interactive-mode'.
2442 To specify a coding system for converting non-ASCII characters
2443 in the input and output to the process, use \\[universal-coding-system-argument]
2444 before \\[sql-oracle]. You can also specify this with \\[set-buffer-process-coding-system]
2445 in the SQL buffer, after you start the process.
2446 The default comes from `process-coding-system-alist' and
2447 `default-process-coding-system'.
2449 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2450 (interactive)
2451 (sql-product-interactive 'oracle))
2453 (defun sql-connect-oracle ()
2454 "Create comint buffer and connect to Oracle using the login
2455 parameters and command options."
2456 ;; Produce user/password@database construct. Password without user
2457 ;; is meaningless; database without user/password is meaningless,
2458 ;; because "@param" will ask sqlplus to interpret the script
2459 ;; "param".
2460 (let ((parameter nil))
2461 (if (not (string= "" sql-user))
2462 (if (not (string= "" sql-password))
2463 (setq parameter (concat sql-user "/" sql-password))
2464 (setq parameter sql-user)))
2465 (if (and parameter (not (string= "" sql-database)))
2466 (setq parameter (concat parameter "@" sql-database)))
2467 (if parameter
2468 (setq parameter (nconc (list parameter) sql-oracle-options))
2469 (setq parameter sql-oracle-options))
2470 (if parameter
2471 (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil
2472 parameter))
2473 (set-buffer (make-comint "SQL" sql-oracle-program nil)))
2474 ;; SQL*Plus is buffered on WindowsNT; this handles &placeholders.
2475 (if (eq window-system 'w32)
2476 (setq comint-input-sender 'sql-query-placeholders-and-send))))
2480 ;;;###autoload
2481 (defun sql-sybase ()
2482 "Run isql by SyBase as an inferior process.
2484 If buffer `*SQL*' exists but no process is running, make a new process.
2485 If buffer exists and a process is running, just switch to buffer
2486 `*SQL*'.
2488 Interpreter used comes from variable `sql-sybase-program'. Login uses
2489 the variables `sql-server', `sql-user', `sql-password', and
2490 `sql-database' as defaults, if set. Additional command line parameters
2491 can be stored in the list `sql-sybase-options'.
2493 The buffer is put in sql-interactive-mode, giving commands for sending
2494 input. See `sql-interactive-mode'.
2496 To specify a coding system for converting non-ASCII characters
2497 in the input and output to the process, use \\[universal-coding-system-argument]
2498 before \\[sql-sybase]. You can also specify this with \\[set-buffer-process-coding-system]
2499 in the SQL buffer, after you start the process.
2500 The default comes from `process-coding-system-alist' and
2501 `default-process-coding-system'.
2503 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2504 (interactive)
2505 (sql-product-interactive 'sybase))
2507 (defun sql-connect-sybase ()
2508 "Create comint buffer and connect to Sybase using the login
2509 parameters and command options."
2510 ;; Put all parameters to the program (if defined) in a list and call
2511 ;; make-comint.
2512 (let ((params sql-sybase-options))
2513 (if (not (string= "" sql-server))
2514 (setq params (append (list "-S" sql-server) params)))
2515 (if (not (string= "" sql-database))
2516 (setq params (append (list "-D" sql-database) params)))
2517 (if (not (string= "" sql-password))
2518 (setq params (append (list "-P" sql-password) params)))
2519 (if (not (string= "" sql-user))
2520 (setq params (append (list "-U" sql-user) params)))
2521 (set-buffer (apply 'make-comint "SQL" sql-sybase-program
2522 nil params))))
2526 ;;;###autoload
2527 (defun sql-informix ()
2528 "Run dbaccess by Informix as an inferior process.
2530 If buffer `*SQL*' exists but no process is running, make a new process.
2531 If buffer exists and a process is running, just switch to buffer
2532 `*SQL*'.
2534 Interpreter used comes from variable `sql-informix-program'. Login uses
2535 the variable `sql-database' as default, if set.
2537 The buffer is put in sql-interactive-mode, giving commands for sending
2538 input. See `sql-interactive-mode'.
2540 To specify a coding system for converting non-ASCII characters
2541 in the input and output to the process, use \\[universal-coding-system-argument]
2542 before \\[sql-informix]. You can also specify this with \\[set-buffer-process-coding-system]
2543 in the SQL buffer, after you start the process.
2544 The default comes from `process-coding-system-alist' and
2545 `default-process-coding-system'.
2547 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2548 (interactive)
2549 (sql-product-interactive 'informix))
2551 (defun sql-connect-informix ()
2552 "Create comint buffer and connect to Informix using the login
2553 parameters and command options."
2554 ;; username and password are ignored.
2555 (if (string= "" sql-database)
2556 (set-buffer (make-comint "SQL" sql-informix-program nil))
2557 (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-"))))
2561 ;;;###autoload
2562 (defun sql-sqlite ()
2563 "Run sqlite as an inferior process.
2565 SQLite is free software.
2567 If buffer `*SQL*' exists but no process is running, make a new process.
2568 If buffer exists and a process is running, just switch to buffer
2569 `*SQL*'.
2571 Interpreter used comes from variable `sql-sqlite-program'. Login uses
2572 the variables `sql-user', `sql-password', `sql-database', and
2573 `sql-server' as defaults, if set. Additional command line parameters
2574 can be stored in the list `sql-sqlite-options'.
2576 The buffer is put in sql-interactive-mode, giving commands for sending
2577 input. See `sql-interactive-mode'.
2579 To specify a coding system for converting non-ASCII characters
2580 in the input and output to the process, use \\[universal-coding-system-argument]
2581 before \\[sql-sqlite]. You can also specify this with \\[set-buffer-process-coding-system]
2582 in the SQL buffer, after you start the process.
2583 The default comes from `process-coding-system-alist' and
2584 `default-process-coding-system'.
2586 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2587 (interactive)
2588 (sql-product-interactive 'sqlite))
2590 (defun sql-connect-sqlite ()
2591 "Create comint buffer and connect to SQLite using the login
2592 parameters and command options."
2593 ;; Put all parameters to the program (if defined) in a list and call
2594 ;; make-comint.
2595 (let ((params))
2596 (if (not (string= "" sql-database))
2597 (setq params (append (list sql-database) params)))
2598 (if (not (string= "" sql-server))
2599 (setq params (append (list (concat "--host=" sql-server)) params)))
2600 (if (not (string= "" sql-password))
2601 (setq params (append (list (concat "--password=" sql-password)) params)))
2602 (if (not (string= "" sql-user))
2603 (setq params (append (list (concat "--user=" sql-user)) params)))
2604 (if (not (null sql-sqlite-options))
2605 (setq params (append sql-sqlite-options params)))
2606 (set-buffer (apply 'make-comint "SQL" sql-sqlite-program
2607 nil params))))
2611 ;;;###autoload
2612 (defun sql-mysql ()
2613 "Run mysql by TcX as an inferior process.
2615 Mysql versions 3.23 and up are free software.
2617 If buffer `*SQL*' exists but no process is running, make a new process.
2618 If buffer exists and a process is running, just switch to buffer
2619 `*SQL*'.
2621 Interpreter used comes from variable `sql-mysql-program'. Login uses
2622 the variables `sql-user', `sql-password', `sql-database', and
2623 `sql-server' as defaults, if set. Additional command line parameters
2624 can be stored in the list `sql-mysql-options'.
2626 The buffer is put in sql-interactive-mode, giving commands for sending
2627 input. See `sql-interactive-mode'.
2629 To specify a coding system for converting non-ASCII characters
2630 in the input and output to the process, use \\[universal-coding-system-argument]
2631 before \\[sql-mysql]. You can also specify this with \\[set-buffer-process-coding-system]
2632 in the SQL buffer, after you start the process.
2633 The default comes from `process-coding-system-alist' and
2634 `default-process-coding-system'.
2636 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2637 (interactive)
2638 (sql-product-interactive 'mysql))
2640 (defun sql-connect-mysql ()
2641 "Create comint buffer and connect to MySQL using the login
2642 parameters and command options."
2643 ;; Put all parameters to the program (if defined) in a list and call
2644 ;; make-comint.
2645 (let ((params))
2646 (if (not (string= "" sql-database))
2647 (setq params (append (list sql-database) params)))
2648 (if (not (string= "" sql-server))
2649 (setq params (append (list (concat "--host=" sql-server)) params)))
2650 (if (not (string= "" sql-password))
2651 (setq params (append (list (concat "--password=" sql-password)) params)))
2652 (if (not (string= "" sql-user))
2653 (setq params (append (list (concat "--user=" sql-user)) params)))
2654 (if (not (null sql-mysql-options))
2655 (setq params (append sql-mysql-options params)))
2656 (set-buffer (apply 'make-comint "SQL" sql-mysql-program
2657 nil params))))
2661 ;;;###autoload
2662 (defun sql-solid ()
2663 "Run solsql by Solid as an inferior process.
2665 If buffer `*SQL*' exists but no process is running, make a new process.
2666 If buffer exists and a process is running, just switch to buffer
2667 `*SQL*'.
2669 Interpreter used comes from variable `sql-solid-program'. Login uses
2670 the variables `sql-user', `sql-password', and `sql-server' as
2671 defaults, if set.
2673 The buffer is put in sql-interactive-mode, giving commands for sending
2674 input. See `sql-interactive-mode'.
2676 To specify a coding system for converting non-ASCII characters
2677 in the input and output to the process, use \\[universal-coding-system-argument]
2678 before \\[sql-solid]. You can also specify this with \\[set-buffer-process-coding-system]
2679 in the SQL buffer, after you start the process.
2680 The default comes from `process-coding-system-alist' and
2681 `default-process-coding-system'.
2683 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2684 (interactive)
2685 (sql-product-interactive 'solid))
2687 (defun sql-connect-solid ()
2688 "Create comint buffer and connect to Solid using the login
2689 parameters and command options."
2690 ;; Put all parameters to the program (if defined) in a list and call
2691 ;; make-comint.
2692 (let ((params))
2693 ;; It only makes sense if both username and password are there.
2694 (if (not (or (string= "" sql-user)
2695 (string= "" sql-password)))
2696 (setq params (append (list sql-user sql-password) params)))
2697 (if (not (string= "" sql-server))
2698 (setq params (append (list sql-server) params)))
2699 (set-buffer (apply 'make-comint "SQL" sql-solid-program
2700 nil params))))
2704 ;;;###autoload
2705 (defun sql-ingres ()
2706 "Run sql by Ingres as an inferior process.
2708 If buffer `*SQL*' exists but no process is running, make a new process.
2709 If buffer exists and a process is running, just switch to buffer
2710 `*SQL*'.
2712 Interpreter used comes from variable `sql-ingres-program'. Login uses
2713 the variable `sql-database' as default, if set.
2715 The buffer is put in sql-interactive-mode, giving commands for sending
2716 input. See `sql-interactive-mode'.
2718 To specify a coding system for converting non-ASCII characters
2719 in the input and output to the process, use \\[universal-coding-system-argument]
2720 before \\[sql-ingres]. You can also specify this with \\[set-buffer-process-coding-system]
2721 in the SQL buffer, after you start the process.
2722 The default comes from `process-coding-system-alist' and
2723 `default-process-coding-system'.
2725 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2726 (interactive)
2727 (sql-product-interactive 'ingres))
2729 (defun sql-connect-ingres ()
2730 "Create comint buffer and connect to Ingres using the login
2731 parameters and command options."
2732 ;; username and password are ignored.
2733 (if (string= "" sql-database)
2734 (set-buffer (make-comint "SQL" sql-ingres-program nil))
2735 (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database))))
2739 ;;;###autoload
2740 (defun sql-ms ()
2741 "Run osql by Microsoft as an inferior process.
2743 If buffer `*SQL*' exists but no process is running, make a new process.
2744 If buffer exists and a process is running, just switch to buffer
2745 `*SQL*'.
2747 Interpreter used comes from variable `sql-ms-program'. Login uses the
2748 variables `sql-user', `sql-password', `sql-database', and `sql-server'
2749 as defaults, if set. Additional command line parameters can be stored
2750 in the list `sql-ms-options'.
2752 The buffer is put in sql-interactive-mode, giving commands for sending
2753 input. See `sql-interactive-mode'.
2755 To specify a coding system for converting non-ASCII characters
2756 in the input and output to the process, use \\[universal-coding-system-argument]
2757 before \\[sql-ms]. You can also specify this with \\[set-buffer-process-coding-system]
2758 in the SQL buffer, after you start the process.
2759 The default comes from `process-coding-system-alist' and
2760 `default-process-coding-system'.
2762 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2763 (interactive)
2764 (sql-product-interactive 'ms))
2766 (defun sql-connect-ms ()
2767 "Create comint buffer and connect to Microsoft using the login
2768 parameters and command options."
2769 ;; Put all parameters to the program (if defined) in a list and call
2770 ;; make-comint.
2771 (let ((params sql-ms-options))
2772 (if (not (string= "" sql-server))
2773 (setq params (append (list "-S" sql-server) params)))
2774 (if (not (string= "" sql-database))
2775 (setq params (append (list "-d" sql-database) params)))
2776 (if (not (string= "" sql-user))
2777 (setq params (append (list "-U" sql-user) params)))
2778 (if (not (string= "" sql-password))
2779 (setq params (append (list "-P" sql-password) params))
2780 (if (string= "" sql-user)
2781 ;; if neither user nor password is provided, use system
2782 ;; credentials.
2783 (setq params (append (list "-E") params))
2784 ;; If -P is passed to ISQL as the last argument without a
2785 ;; password, it's considered null.
2786 (setq params (append params (list "-P")))))
2787 (set-buffer (apply 'make-comint "SQL" sql-ms-program
2788 nil params))))
2792 ;;;###autoload
2793 (defun sql-postgres ()
2794 "Run psql by Postgres as an inferior process.
2796 If buffer `*SQL*' exists but no process is running, make a new process.
2797 If buffer exists and a process is running, just switch to buffer
2798 `*SQL*'.
2800 Interpreter used comes from variable `sql-postgres-program'. Login uses
2801 the variables `sql-database' and `sql-server' as default, if set.
2802 Additional command line parameters can be stored in the list
2803 `sql-postgres-options'.
2805 The buffer is put in sql-interactive-mode, giving commands for sending
2806 input. See `sql-interactive-mode'.
2808 To specify a coding system for converting non-ASCII characters
2809 in the input and output to the process, use \\[universal-coding-system-argument]
2810 before \\[sql-postgres]. You can also specify this with \\[set-buffer-process-coding-system]
2811 in the SQL buffer, after you start the process.
2812 The default comes from `process-coding-system-alist' and
2813 `default-process-coding-system'. If your output lines end with ^M,
2814 your might try undecided-dos as a coding system. If this doesn't help,
2815 Try to set `comint-output-filter-functions' like this:
2817 \(setq comint-output-filter-functions (append comint-output-filter-functions
2818 '(comint-strip-ctrl-m)))
2820 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2821 (interactive)
2822 (sql-product-interactive 'postgres))
2824 (defun sql-connect-postgres ()
2825 "Create comint buffer and connect to Postgres using the login
2826 parameters and command options."
2827 ;; username and password are ignored. Mark Stosberg suggest to add
2828 ;; the database at the end. Jason Beegan suggest using --pset and
2829 ;; pager=off instead of \\o|cat. The later was the solution by
2830 ;; Gregor Zych. Jason's suggestion is the default value for
2831 ;; sql-postgres-options.
2832 (let ((params sql-postgres-options))
2833 (if (not (string= "" sql-database))
2834 (setq params (append params (list sql-database))))
2835 (if (not (string= "" sql-server))
2836 (setq params (append (list "-h" sql-server) params)))
2837 (if (not (string= "" sql-user))
2838 (setq params (append (list "-U" sql-user) params)))
2839 (set-buffer (apply 'make-comint "SQL" sql-postgres-program
2840 nil params))))
2844 ;;;###autoload
2845 (defun sql-interbase ()
2846 "Run isql by Interbase as an inferior process.
2848 If buffer `*SQL*' exists but no process is running, make a new process.
2849 If buffer exists and a process is running, just switch to buffer
2850 `*SQL*'.
2852 Interpreter used comes from variable `sql-interbase-program'. Login
2853 uses the variables `sql-user', `sql-password', and `sql-database' as
2854 defaults, if set.
2856 The buffer is put in sql-interactive-mode, giving commands for sending
2857 input. See `sql-interactive-mode'.
2859 To specify a coding system for converting non-ASCII characters
2860 in the input and output to the process, use \\[universal-coding-system-argument]
2861 before \\[sql-interbase]. You can also specify this with \\[set-buffer-process-coding-system]
2862 in the SQL buffer, after you start the process.
2863 The default comes from `process-coding-system-alist' and
2864 `default-process-coding-system'.
2866 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2867 (interactive)
2868 (sql-product-interactive 'interbase))
2870 (defun sql-connect-interbase ()
2871 "Create comint buffer and connect to Interbase using the login
2872 parameters and command options."
2873 ;; Put all parameters to the program (if defined) in a list and call
2874 ;; make-comint.
2875 (let ((params sql-interbase-options))
2876 (if (not (string= "" sql-user))
2877 (setq params (append (list "-u" sql-user) params)))
2878 (if (not (string= "" sql-password))
2879 (setq params (append (list "-p" sql-password) params)))
2880 (if (not (string= "" sql-database))
2881 (setq params (cons sql-database params))) ; add to the front!
2882 (set-buffer (apply 'make-comint "SQL" sql-interbase-program
2883 nil params))))
2887 ;;;###autoload
2888 (defun sql-db2 ()
2889 "Run db2 by IBM as an inferior process.
2891 If buffer `*SQL*' exists but no process is running, make a new process.
2892 If buffer exists and a process is running, just switch to buffer
2893 `*SQL*'.
2895 Interpreter used comes from variable `sql-db2-program'. There is not
2896 automatic login.
2898 The buffer is put in sql-interactive-mode, giving commands for sending
2899 input. See `sql-interactive-mode'.
2901 If you use \\[sql-accumulate-and-indent] to send multiline commands to
2902 db2, newlines will be escaped if necessary. If you don't want that, set
2903 `comint-input-sender' back to `comint-simple-send' by writing an after
2904 advice. See the elisp manual for more information.
2906 To specify a coding system for converting non-ASCII characters
2907 in the input and output to the process, use \\[universal-coding-system-argument]
2908 before \\[sql-db2]. You can also specify this with \\[set-buffer-process-coding-system]
2909 in the SQL buffer, after you start the process.
2910 The default comes from `process-coding-system-alist' and
2911 `default-process-coding-system'.
2913 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2914 (interactive)
2915 (sql-product-interactive 'db2))
2917 (defun sql-connect-db2 ()
2918 "Create comint buffer and connect to DB2 using the login
2919 parameters and command options."
2920 ;; Put all parameters to the program (if defined) in a list and call
2921 ;; make-comint.
2922 (set-buffer (apply 'make-comint "SQL" sql-db2-program
2923 nil sql-db2-options))
2924 ;; Properly escape newlines when DB2 is interactive.
2925 (setq comint-input-sender 'sql-escape-newlines-and-send))
2927 ;;;###autoload
2928 (defun sql-linter ()
2929 "Run inl by RELEX as an inferior process.
2931 If buffer `*SQL*' exists but no process is running, make a new process.
2932 If buffer exists and a process is running, just switch to buffer
2933 `*SQL*'.
2935 Interpreter used comes from variable `sql-linter-program' - usually `inl'.
2936 Login uses the variables `sql-user', `sql-password', `sql-database' and
2937 `sql-server' as defaults, if set. Additional command line parameters
2938 can be stored in the list `sql-linter-options'. Run inl -h to get help on
2939 parameters.
2941 `sql-database' is used to set the LINTER_MBX environment variable for
2942 local connections, `sql-server' refers to the server name from the
2943 `nodetab' file for the network connection (dbc_tcp or friends must run
2944 for this to work). If `sql-password' is an empty string, inl will use
2945 an empty password.
2947 The buffer is put in sql-interactive-mode, giving commands for sending
2948 input. See `sql-interactive-mode'.
2950 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2951 (interactive)
2952 (sql-product-interactive 'linter))
2954 (defun sql-connect-linter ()
2955 "Create comint buffer and connect to Linter using the login
2956 parameters and command options."
2957 ;; Put all parameters to the program (if defined) in a list and call
2958 ;; make-comint.
2959 (let ((params sql-linter-options) (login nil) (old-mbx (getenv "LINTER_MBX")))
2960 (if (not (string= "" sql-user))
2961 (setq login (concat sql-user "/" sql-password)))
2962 (setq params (append (list "-u" login) params))
2963 (if (not (string= "" sql-server))
2964 (setq params (append (list "-n" sql-server) params)))
2965 (if (string= "" sql-database)
2966 (setenv "LINTER_MBX" nil)
2967 (setenv "LINTER_MBX" sql-database))
2968 (set-buffer (apply 'make-comint "SQL" sql-linter-program nil
2969 params))
2970 (setenv "LINTER_MBX" old-mbx)))
2974 (provide 'sql)
2976 ;;; arch-tag: 7e1fa1c4-9ca2-402e-87d2-83a5eccb7ac3
2977 ;;; sql.el ends here