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