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