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