(all): Make `indicate-buffer-boundaries' display values set outside
[bpt/emacs.git] / lisp / progmodes / sql.el
1 ;;; sql.el --- specialized comint.el for SQL interpreters
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 ;; Free Software Foundation, Inc.
5
6 ;; Author: Alex Schroeder <alex@gnu.org>
7 ;; Maintainer: Michael Mauger <mmaug@yahoo.com>
8 ;; Version: 2.0.1
9 ;; Keywords: comm languages processes
10 ;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el
11 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode
12
13 ;; This file is part of GNU Emacs.
14
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; any later version.
19
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.
24
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.
29
30 ;;; Commentary:
31
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.
36
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.
43
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.
48
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.
53
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).
57
58 ;; Since sql-interactive-mode is built on top of the general
59 ;; command-interpreter-in-a-buffer mode (comint mode), it shares a
60 ;; common base functionality, and a common set of bindings, with all
61 ;; modes derived from comint mode. This makes these modes easier to
62 ;; use.
63
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.
66
67 ;; For documentation on the functionality provided by comint mode, and
68 ;; the hooks available for customizing it, see the file `comint.el'.
69
70 ;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and
71 ;; `imenu-add-menubar-index'.
72
73 ;;; Requirements for Emacs 19.34:
74
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/>.
80
81 ;;; Bugs:
82
83 ;; sql-ms now uses osql instead of isql. Osql flushes its error
84 ;; stream more frequently than isql so that error messages are
85 ;; available. There is no prompt and some output still is buffered.
86 ;; This improves the interaction under Emacs but it still is somewhat
87 ;; awkward.
88
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 [].
93
94 ;; ChangeLog available on request.
95
96 ;;; Product Support:
97
98 ;; To add support for additional SQL products the following steps
99 ;; must be followed ("xyz" is the name of the product in the examples
100 ;; below):
101
102 ;; 1) Add the product to `sql-product' choice list.
103
104 ;; (const :tag "XyzDB" xyz)
105
106 ;; 2) Add an entry to the `sql-product-alist' list.
107
108 ;; (xyz
109 ;; :font-lock sql-mode-xyz-font-lock-keywords
110 ;; :sqli-login (user password server database)
111 ;; :sqli-connect sql-connect-xyz
112 ;; :sqli-prompt-regexp "^xyzdb> "
113 ;; :sqli-prompt-length 7
114 ;; :sqli-input-sender nil
115 ;; :syntax-alist ((?# . "w")))
116
117 ;; 3) Add customizable values for the product interpreter and options.
118
119 ;; ;; Customization for XyzDB
120 ;;
121 ;; (defcustom sql-xyz-program "ixyz"
122 ;; "*Command to start ixyz by XyzDB."
123 ;; :type 'file
124 ;; :group 'SQL)
125 ;;
126 ;; (defcustom sql-xyz-options '("-X" "-Y" "-Z")
127 ;; "*List of additional options for `sql-xyz-program'."
128 ;; :type '(repeat string)
129 ;; :group 'SQL)
130
131 ;; 4) Add an entry to SQL->Product submenu.
132
133 ;; ["XyzDB" sql-highlight-xyz-keywords
134 ;; :style radio
135 ;; :selected (eq sql-product 'xyz)]
136
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.
140
141 ;; (defvar sql-mode-xyz-font-lock-keywords nil
142 ;; "XyzDB SQL keywords used by font-lock.")
143
144 ;; 6) Add a product highlighting function.
145
146 ;; (defun sql-highlight-xyz-keywords ()
147 ;; "Highlight XyzDB keywords."
148 ;; (interactive)
149 ;; (sql-set-product 'xyz))
150
151 ;; 7) Add an autoloaded SQLi function.
152
153 ;; ;;;###autoload
154 ;; (defun sql-xyz ()
155 ;; "Run ixyz by XyzDB as an inferior process."
156 ;; (interactive)
157 ;; (sql-product-interactive 'xyz))
158
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.
163
164 ;; (defun sql-connect-xyz ()
165 ;; "Create comint buffer and connect to XyzDB using the login
166 ;; parameters and command options."
167 ;;
168 ;; ;; Do something with `sql-user', `sql-password',
169 ;; ;; `sql-database', and `sql-server'.
170 ;; (let ((params sql-xyz-options))
171 ;; (if (not (string= "" sql-server))
172 ;; (setq params (append (list "-S" sql-server) params)))
173 ;; (if (not (string= "" sql-database))
174 ;; (setq params (append (list "-D" sql-database) params)))
175 ;; (if (not (string= "" sql-password))
176 ;; (setq params (append (list "-P" sql-password) params)))
177 ;; (if (not (string= "" sql-user))
178 ;; (setq params (append (list "-U" sql-user) params)))
179 ;; (set-buffer (apply 'make-comint "SQL" sql-xyz-program
180 ;; nil params))))
181
182 ;; 9) Save and compile sql.el.
183
184 ;;; To Do:
185
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.
192
193 ;; Add different hilighting levels.
194
195 ;;; Thanks to all the people who helped me out:
196
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
209
210 \f
211
212 ;;; Code:
213
214 (require 'comint)
215 ;; Need the following to allow GNU Emacs 19 to compile the file.
216 (eval-when-compile
217 (require 'regexp-opt))
218 (require 'custom)
219 (eval-when-compile ;; needed in Emacs 19, 20
220 (setq max-specpdl-size 2000))
221
222 ;;; Allow customization
223
224 (defgroup SQL nil
225 "Running a SQL interpreter from within Emacs buffers."
226 :version "20.4"
227 :group 'processes)
228
229 ;; These four variables will be used as defaults, if set.
230
231 (defcustom sql-user ""
232 "*Default username."
233 :type 'string
234 :group 'SQL)
235
236 (defcustom sql-password ""
237 "*Default password.
238
239 Storing your password in a textfile such as ~/.emacs could be dangerous.
240 Customizing your password will store it in your ~/.emacs file."
241 :type 'string
242 :group 'SQL)
243
244 (defcustom sql-database ""
245 "*Default database."
246 :type 'string
247 :group 'SQL)
248
249 (defcustom sql-server ""
250 "*Default server or host."
251 :type 'string
252 :group 'SQL)
253
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))
271 :group 'SQL)
272
273 (defvar sql-interactive-product nil
274 "Product under `sql-interactive-mode'.")
275
276 (defvar sql-product-alist
277 '((ansi
278 :font-lock sql-mode-ansi-font-lock-keywords)
279 (db2
280 :font-lock sql-mode-db2-font-lock-keywords
281 :sqli-login nil
282 :sqli-connect sql-connect-db2
283 :sqli-prompt-regexp "^db2 => "
284 :sqli-prompt-length 7)
285 (informix
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)
291 (ingres
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)
297 (interbase
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)
303 (linter
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)
309 (ms
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")))
316 (mysql
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)
322 (oracle
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")))
329 (postgres
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)
335 (solid
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)
341 (sqlite
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)
347 (sybase
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")))
354 )
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'.
359
360 Each element in the list is in the following format:
361
362 \(PRODUCT FEATURE VALUE ...)
363
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
367 following:
368
369 :font-lock name of the variable containing the product
370 specific font lock highlighting patterns.
371
372 :sqli-login a list of login parameters (i.e., user,
373 password, database and server) needed to
374 connect to the database.
375
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.
383
384 :sqli-prompt-regexp a regular expression string that matches
385 the prompt issued by the product
386 interpreter. (Not needed in 21.3+)
387
388 :sqli-prompt-length the length of the prompt on the line.(Not
389 needed in 21.3+)
390
391 :syntax-alist an alist of syntax table entries to enable
392 special character treatment by font-lock and
393 imenu. ")
394
395 ;; misc customization of sql.el behaviour
396
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))
408 :version "20.8"
409 :group 'SQL)
410
411 (defcustom sql-pop-to-buffer-after-send-region nil
412 "*If t, pop to the buffer SQL statements are sent to.
413
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'."
419 :type 'boolean
420 :group 'SQL)
421
422 ;; imenu support for sql-mode.
423
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'.
435
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
439 local variable.")
440
441 ;; history file
442
443 (defcustom sql-input-ring-file-name nil
444 "*If non-nil, name of the file to read/write input history.
445
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.
451
452 This is used to initialize `comint-input-ring-file-name'.
453
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)
457 (file))
458 :group 'SQL)
459
460 (defcustom sql-input-ring-separator "\n--\n"
461 "*Separator between commands in the history file.
462
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.
466
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\"."
473 :type 'string
474 :group 'SQL)
475
476 ;; The usual hooks
477
478 (defcustom sql-interactive-mode-hook '()
479 "*Hook for customizing `sql-interactive-mode'."
480 :type 'hook
481 :group 'SQL)
482
483 (defcustom sql-mode-hook '()
484 "*Hook for customizing `sql-mode'."
485 :type 'hook
486 :group 'SQL)
487
488 (defcustom sql-set-sqli-hook '()
489 "*Hook for reacting to changes of `sql-buffer'.
490
491 This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
492 is changed."
493 :type 'hook
494 :group 'SQL)
495
496 ;; Customization for Oracle
497
498 (defcustom sql-oracle-program "sqlplus"
499 "*Command to start sqlplus by Oracle.
500
501 Starts `sql-interactive-mode' after doing some setup.
502
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.
506
507 The program can also specify a TCP connection. See `make-comint'."
508 :type 'file
509 :group 'SQL)
510
511 (defcustom sql-oracle-options nil
512 "*List of additional options for `sql-oracle-program'."
513 :type '(repeat string)
514 :version "20.8"
515 :group 'SQL)
516
517 ;; Customization for SQLite
518
519 (defcustom sql-sqlite-program "sqlite"
520 "*Command to start SQLite.
521
522 Starts `sql-interactive-mode' after doing some setup.
523
524 The program can also specify a TCP connection. See `make-comint'."
525 :type 'file
526 :group 'SQL)
527
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)
533 :version "20.8"
534 :group 'SQL)
535
536 ;; Customization for MySql
537
538 (defcustom sql-mysql-program "mysql"
539 "*Command to start mysql by TcX.
540
541 Starts `sql-interactive-mode' after doing some setup.
542
543 The program can also specify a TCP connection. See `make-comint'."
544 :type 'file
545 :group 'SQL)
546
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)
552 :version "20.8"
553 :group 'SQL)
554
555 ;; Customization for Solid
556
557 (defcustom sql-solid-program "solsql"
558 "*Command to start SOLID SQL Editor.
559
560 Starts `sql-interactive-mode' after doing some setup.
561
562 The program can also specify a TCP connection. See `make-comint'."
563 :type 'file
564 :group 'SQL)
565
566 ;; Customization for SyBase
567
568 (defcustom sql-sybase-program "isql"
569 "*Command to start isql by SyBase.
570
571 Starts `sql-interactive-mode' after doing some setup.
572
573 The program can also specify a TCP connection. See `make-comint'."
574 :type 'file
575 :group 'SQL)
576
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)
581 :version "20.8"
582 :group 'SQL)
583
584 ;; Customization for Informix
585
586 (defcustom sql-informix-program "dbaccess"
587 "*Command to start dbaccess by Informix.
588
589 Starts `sql-interactive-mode' after doing some setup.
590
591 The program can also specify a TCP connection. See `make-comint'."
592 :type 'file
593 :group 'SQL)
594
595 ;; Customization for Ingres
596
597 (defcustom sql-ingres-program "sql"
598 "*Command to start sql by Ingres.
599
600 Starts `sql-interactive-mode' after doing some setup.
601
602 The program can also specify a TCP connection. See `make-comint'."
603 :type 'file
604 :group 'SQL)
605
606 ;; Customization for Microsoft
607
608 (defcustom sql-ms-program "osql"
609 "*Command to start osql by Microsoft.
610
611 Starts `sql-interactive-mode' after doing some setup.
612
613 The program can also specify a TCP connection. See `make-comint'."
614 :type 'file
615 :group 'SQL)
616
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)
621 :version "22.1"
622 :group 'SQL)
623
624 ;; Customization for Postgres
625
626 (defcustom sql-postgres-program "psql"
627 "Command to start psql by Postgres.
628
629 Starts `sql-interactive-mode' after doing some setup.
630
631 The program can also specify a TCP connection. See `make-comint'."
632 :type 'file
633 :group 'SQL)
634
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)
644 :version "20.8"
645 :group 'SQL)
646
647 ;; Customization for Interbase
648
649 (defcustom sql-interbase-program "isql"
650 "*Command to start isql by Interbase.
651
652 Starts `sql-interactive-mode' after doing some setup.
653
654 The program can also specify a TCP connection. See `make-comint'."
655 :type 'file
656 :group 'SQL)
657
658 (defcustom sql-interbase-options nil
659 "*List of additional options for `sql-interbase-program'."
660 :type '(repeat string)
661 :version "20.8"
662 :group 'SQL)
663
664 ;; Customization for DB2
665
666 (defcustom sql-db2-program "db2"
667 "*Command to start db2 by IBM.
668
669 Starts `sql-interactive-mode' after doing some setup.
670
671 The program can also specify a TCP connection. See `make-comint'."
672 :type 'file
673 :group 'SQL)
674
675 (defcustom sql-db2-options nil
676 "*List of additional options for `sql-db2-program'."
677 :type '(repeat string)
678 :version "20.8"
679 :group 'SQL)
680
681 ;; Customization for Linter
682
683 (defcustom sql-linter-program "inl"
684 "*Command to start inl by RELEX.
685
686 Starts `sql-interactive-mode' after doing some setup."
687 :type 'file
688 :group 'SQL)
689
690 (defcustom sql-linter-options nil
691 "*List of additional options for `sql-linter-program'."
692 :type '(repeat string)
693 :version "21.3"
694 :group 'SQL)
695
696 \f
697
698 ;;; Variables which do not need customization
699
700 (defvar sql-user-history nil
701 "History of usernames used.")
702
703 (defvar sql-database-history nil
704 "History of databases used.")
705
706 (defvar sql-server-history nil
707 "History of servers used.")
708
709 ;; Passwords are not kept in a history.
710
711 (defvar sql-buffer nil
712 "Current SQLi buffer.
713
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].")
719
720 (defvar sql-prompt-regexp nil
721 "Prompt used to initialize `comint-prompt-regexp'.
722
723 You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.")
724
725 (defvar sql-prompt-length 0
726 "Prompt used to set `left-margin' in `sql-interactive-mode'.
727
728 You can change `sql-prompt-length' on `sql-interactive-mode-hook'.")
729
730 (defvar sql-alternate-buffer-name nil
731 "Buffer-local string used to possibly rename the SQLi buffer.
732
733 Used by `sql-rename-buffer'.")
734
735 ;; Keymap for sql-interactive-mode.
736
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)
749 map)
750 "Mode map used for `sql-interactive-mode'.
751 Based on `comint-mode-map'.")
752
753 ;; Keymap for sql-mode.
754
755 (defvar sql-mode-map
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)
761 map)
762 "Mode map used for `sql-mode'.")
763
764 ;; easy menu for sql-mode.
765
766 (easy-menu-define
767 sql-mode-menu sql-mode-map
768 "Menu for `sql-mode'."
769 '("SQL"
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
773 mark-active)
774 (mark t)); XEmacs
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]
780 ["--" nil nil]
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
786 :style toggle
787 :selected sql-pop-to-buffer-after-send-region]
788 ["--" nil nil]
789 ("Product"
790 ["ANSI" sql-highlight-ansi-keywords
791 :style radio
792 :selected (eq sql-product 'ansi)]
793 ["DB2" sql-highlight-db2-keywords
794 :style radio
795 :selected (eq sql-product 'db2)]
796 ["Informix" sql-highlight-informix-keywords
797 :style radio
798 :selected (eq sql-product 'informix)]
799 ["Ingres" sql-highlight-ingres-keywords
800 :style radio
801 :selected (eq sql-product 'ingres)]
802 ["Interbase" sql-highlight-interbase-keywords
803 :style radio
804 :selected (eq sql-product 'interbase)]
805 ["Linter" sql-highlight-linter-keywords
806 :style radio
807 :selected (eq sql-product 'linter)]
808 ["MS SQLServer" sql-highlight-ms-keywords
809 :style radio
810 :selected (eq sql-product 'ms)]
811 ["MySQL" sql-highlight-mysql-keywords
812 :style radio
813 :selected (eq sql-product 'mysql)]
814 ["Oracle" sql-highlight-oracle-keywords
815 :style radio
816 :selected (eq sql-product 'oracle)]
817 ["Postgres" sql-highlight-postgres-keywords
818 :style radio
819 :selected (eq sql-product 'postgres)]
820 ["Solid" sql-highlight-solid-keywords
821 :style radio
822 :selected (eq sql-product 'solid)]
823 ["SQLite" sql-highlight-sqlite-keywords
824 :style radio
825 :selected (eq sql-product 'sqlite)]
826 ["Sybase" sql-highlight-sybase-keywords
827 :style radio
828 :selected (eq sql-product 'sybase)]
829 )))
830
831 ;; easy menu for sql-interactive-mode.
832
833 (easy-menu-define
834 sql-interactive-mode-menu sql-interactive-mode-map
835 "Menu for `sql-interactive-mode'."
836 '("SQL"
837 ["Rename Buffer" sql-rename-buffer t]))
838
839 ;; Abbreviations -- if you want more of them, define them in your
840 ;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too.
841
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)
846 (mapcar
847 ;; In Emacs 21.3+, provide SYSTEM-FLAG to define-abbrev.
848 '(lambda (abbrev)
849 (let ((name (car abbrev))
850 (expansion (cdr abbrev)))
851 (condition-case nil
852 (define-abbrev sql-mode-abbrev-table name expansion nil 0 t)
853 (error
854 (define-abbrev sql-mode-abbrev-table name expansion)))))
855 '(("ins" "insert")
856 ("upd" "update")
857 ("del" "delete")
858 ("sel" "select")
859 ("proc" "procedure")
860 ("func" "function")
861 ("cr" "create"))))
862
863 ;; Syntax Table
864
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)
879 table)
880 "Syntax table used in `sql-mode' and `sql-interactive-mode'.")
881
882 ;; Font lock support
883
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-+"
889 "\\(\\w+\\)")
890 6 'font-lock-function-name-face)
891
892 "Pattern to match the names of top-level objects.
893
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.")
897
898 (defmacro sql-keywords-re (&rest keywords)
899 "Compile-time generation of regexp matching any one of KEYWORDS."
900 `(eval-when-compile
901 (concat "\\b"
902 (regexp-opt ',keywords t)
903 "\\b")))
904
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"
913 "user"
914 ))
915
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"
944 ))
945
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"
982 ))
983
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"
989 "varying" "zone"
990 )))
991
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)))
996
997 "ANSI SQL keywords used by font-lock.
998
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.")
1004
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"
1037 ))
1038
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"
1125 ))
1126
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"
1133 ))
1134
1135 (plsql-functions (sql-keywords-re
1136 "%bulk_rowcount" "%found" "%isopen" "%notfound" "%rowcount" "%rowtype"
1137 "%type" "extend" "prior"
1138 ))
1139
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"
1148 ))
1149
1150 (plsql-type (sql-keywords-re
1151 "binary_integer" "boolean" "naturaln" "pls_integer" "positive"
1152 "positiven" "record" "signtype" "string"
1153 ))
1154
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"
1163 ))
1164
1165 (sqlplus-commands
1166 (eval-when-compile (concat "^\\(\\("
1167 (regexp-opt '(
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"
1175
1176 ) t)
1177
1178 "\\)\\|"
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\\)?\\)\\)\\)"
1201 "\\b.*$"
1202 ))))
1203
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)))
1212
1213 "Oracle SQL keywords used by font-lock.
1214
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.")
1220
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"
1247 ))
1248
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"
1283 "work"
1284 ))
1285
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"
1295 )))
1296
1297 `((,pg-funcs . font-lock-builtin-face)
1298 (,pg-reserved . font-lock-keyword-face)
1299 (,pg-types . font-lock-type-face)))
1300
1301 "Postgres SQL keywords used by font-lock.
1302
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.")
1307
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"
1334 ))
1335
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"
1354 ))
1355
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"
1360 "cursor" "long"
1361 ))
1362
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"
1374 )))
1375
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)))
1380
1381 "Linter SQL keywords used by font-lock.
1382
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'.")
1386
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"
1420 "returns"
1421 ))
1422
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"
1429 ))
1430
1431 (ms-vars "\\b@[a-zA-Z0-9_]*\\b")
1432
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"
1462 ))
1463
1464 (ms-commands
1465 (eval-when-compile
1466 (concat "^\\(\\(set\\s-+\\("
1467 (regexp-opt '(
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"
1478 ) t)
1479 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$"))))
1480
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)))
1486
1487 "Microsoft SQLServer SQL keywords used by font-lock.
1488
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.")
1493
1494 (defvar sql-mode-sybase-font-lock-keywords nil
1495 "Sybase SQL keywords used by font-lock.
1496
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.")
1501
1502 (defvar sql-mode-informix-font-lock-keywords nil
1503 "Informix SQL keywords used by font-lock.
1504
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.")
1509
1510 (defvar sql-mode-interbase-font-lock-keywords nil
1511 "Interbase SQL keywords used by font-lock.
1512
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.")
1517
1518 (defvar sql-mode-ingres-font-lock-keywords nil
1519 "Ingres SQL keywords used by font-lock.
1520
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.")
1525
1526 (defvar sql-mode-solid-font-lock-keywords nil
1527 "Solid SQL keywords used by font-lock.
1528
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.")
1533
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"
1558 ))
1559
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"
1586 ))
1587
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"
1597 "zerofill"
1598 )))
1599
1600 `((,mysql-funcs . font-lock-builtin-face)
1601 (,mysql-keywords . font-lock-keyword-face)
1602 (,mysql-types . font-lock-type-face)))
1603
1604 "MySQL SQL keywords used by font-lock.
1605
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.")
1610
1611 (defvar sql-mode-sqlite-font-lock-keywords nil
1612 "SQLite SQL keywords used by font-lock.
1613
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.")
1618
1619 (defvar sql-mode-db2-font-lock-keywords nil
1620 "DB2 SQL keywords used by font-lock.
1621
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.")
1626
1627 (defvar sql-mode-font-lock-keywords nil
1628 "SQL keywords used by font-lock.
1629
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.")
1633
1634 \f
1635
1636 ;;; SQL Product support functions
1637
1638 (defun sql-product-feature (feature &optional product)
1639 "Lookup `feature' needed to support the current SQL product.
1640
1641 See \[sql-product-alist] for a list of products and supported features."
1642 (plist-get
1643 (cdr (assoc (or product sql-product)
1644 sql-product-alist))
1645 feature))
1646
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'."
1651 (let
1652 ;; Get the product-specific syntax-alist.
1653 ((syntax-alist
1654 (append
1655 (sql-product-feature :syntax-alist)
1656 '((?_ . "w") (?. . "w")))))
1657
1658 ;; Get the product-specific keywords.
1659 (setq sql-mode-font-lock-keywords
1660 (append
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
1666 ;; statements
1667 (list sql-mode-font-lock-object-name)))
1668
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))
1673
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)
1677 font-lock-mode)
1678 (font-lock-mode-internal nil)
1679 (font-lock-mode-internal t))
1680
1681 (add-hook 'font-lock-mode-hook
1682 (lambda ()
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))
1689 nil t)
1690
1691 ;; Setup imenu; it needs the same syntax-alist.
1692 (when imenu
1693 (setq imenu-syntax-alist syntax-alist))))
1694
1695 ;;;###autoload
1696 (defun sql-add-product-keywords (product keywords &optional append)
1697 "Add highlighting KEYWORDS for SQL PRODUCT.
1698
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.
1706
1707 For example:
1708
1709 (sql-add-product-keywords 'ms
1710 '((\"\\\\b\\\\w+_t\\\\b\" . font-lock-type-face)))
1711
1712 adds a fontification pattern to fontify identifiers ending in
1713 `_t' as data types."
1714
1715 (let ((font-lock (sql-product-feature :font-lock product))
1716 old)
1717 (setq old (eval font-lock))
1718 (set font-lock
1719 (if (eq append 'set)
1720 keywords
1721 (if append
1722 (append old keywords)
1723 (append keywords old))))))
1724
1725 \f
1726
1727 ;;; Functions to switch highlighting
1728
1729 (defun sql-highlight-product ()
1730 "Turns on the appropriate font highlighting for the SQL product
1731 selected."
1732
1733 (when (eq major-mode 'sql-mode)
1734 ;; Setup font-lock
1735 (sql-product-font-lock nil t)
1736
1737 ;; Set the mode name to include the product.
1738 (setq mode-name (concat "SQL[" (prin1-to-string sql-product) "]"))))
1739
1740 (defun sql-set-product (product)
1741 "Set `sql-product' to product and enable appropriate
1742 highlighting."
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))
1747
1748 ;; Save product setting and fontify.
1749 (setq sql-product product)
1750 (sql-highlight-product))
1751
1752 (defun sql-highlight-oracle-keywords ()
1753 "Highlight Oracle keywords."
1754 (interactive)
1755 (sql-set-product 'oracle))
1756
1757 (defun sql-highlight-postgres-keywords ()
1758 "Highlight Postgres keywords."
1759 (interactive)
1760 (sql-set-product 'postgres))
1761
1762 (defun sql-highlight-linter-keywords ()
1763 "Highlight LINTER keywords."
1764 (interactive)
1765 (sql-set-product 'linter))
1766
1767 (defun sql-highlight-ms-keywords ()
1768 "Highlight Microsoft SQLServer keywords."
1769 (interactive)
1770 (sql-set-product 'ms))
1771
1772 (defun sql-highlight-ansi-keywords ()
1773 "Highlight ANSI SQL keywords."
1774 (interactive)
1775 (sql-set-product 'ansi))
1776
1777 (defun sql-highlight-sybase-keywords ()
1778 "Highlight Sybase SQL keywords."
1779 (interactive)
1780 (sql-set-product 'sybase))
1781
1782 (defun sql-highlight-informix-keywords ()
1783 "Highlight Informix SQL keywords."
1784 (interactive)
1785 (sql-set-product 'informix))
1786
1787 (defun sql-highlight-interbase-keywords ()
1788 "Highlight Interbase SQL keywords."
1789 (interactive)
1790 (sql-set-product 'interbase))
1791
1792 (defun sql-highlight-ingres-keywords ()
1793 "Highlight Ingres SQL keywords."
1794 (interactive)
1795 (sql-set-product 'ingres))
1796
1797 (defun sql-highlight-solid-keywords ()
1798 "Highlight Solid SQL keywords."
1799 (interactive)
1800 (sql-set-product 'solid))
1801
1802 (defun sql-highlight-mysql-keywords ()
1803 "Highlight MySQL SQL keywords."
1804 (interactive)
1805 (sql-set-product 'mysql))
1806
1807 (defun sql-highlight-sqlite-keywords ()
1808 "Highlight SQLite SQL keywords."
1809 (interactive)
1810 (sql-set-product 'sqlite))
1811
1812 (defun sql-highlight-db2-keywords ()
1813 "Highlight DB2 SQL keywords."
1814 (interactive)
1815 (sql-set-product 'db2))
1816
1817 \f
1818
1819 ;;; Compatibility functions
1820
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))))
1828
1829 \f
1830
1831 ;;; Small functions
1832
1833 (defun sql-magic-go (arg)
1834 "Insert \"o\" and call `comint-send-input'.
1835 `sql-electric-stuff' must be the symbol `go'."
1836 (interactive "P")
1837 (self-insert-command (prefix-numeric-value arg))
1838 (if (and (equal sql-electric-stuff 'go)
1839 (save-excursion
1840 (comint-bol nil)
1841 (looking-at "go\\b")))
1842 (comint-send-input)))
1843
1844 (defun sql-magic-semicolon (arg)
1845 "Insert semicolon and call `comint-send-input'.
1846 `sql-electric-stuff' must be the symbol `semicolon'."
1847 (interactive "P")
1848 (self-insert-command (prefix-numeric-value arg))
1849 (if (equal sql-electric-stuff 'semicolon)
1850 (comint-send-input)))
1851
1852 (defun sql-accumulate-and-indent ()
1853 "Continue SQL statement on the next line."
1854 (interactive)
1855 (if (fboundp 'comint-accumulate)
1856 (comint-accumulate)
1857 (newline))
1858 (indent-according-to-mode))
1859
1860 ;;;###autoload
1861 (defun sql-help ()
1862 "Show short help for the SQL modes.
1863
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.
1866
1867 Use the following commands to start a specific SQL interpreter:
1868
1869 PostGres: \\[sql-postgres]
1870 MySQL: \\[sql-mysql]
1871 SQLite: \\[sql-sqlite]
1872
1873 Other non-free SQL implementations are also supported:
1874
1875 Solid: \\[sql-solid]
1876 Oracle: \\[sql-oracle]
1877 Informix: \\[sql-informix]
1878 Sybase: \\[sql-sybase]
1879 Ingres: \\[sql-ingres]
1880 Microsoft: \\[sql-ms]
1881 DB2: \\[sql-db2]
1882 Interbase: \\[sql-interbase]
1883 Linter: \\[sql-linter]
1884
1885 But we urge you to choose a free implementation instead of these.
1886
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.
1891
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.
1896
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."
1900 (interactive)
1901 (describe-function 'sql-help))
1902
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)))
1914
1915 (defun sql-get-login (&rest what)
1916 "Get username, password and database from the user.
1917
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
1922 in a history.
1923
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
1929 they are provided.
1930
1931 In order to ask the user for username, password and database, call the
1932 function like this: (sql-get-login 'user 'password 'database)."
1933 (interactive)
1934 (while what
1935 (cond
1936 ((eq (car what) 'user) ; user
1937 (setq sql-user
1938 (read-from-minibuffer "User: " sql-user nil nil
1939 sql-user-history)))
1940 ((eq (car what) 'password) ; password
1941 (setq sql-password
1942 (sql-read-passwd "Password: " sql-password)))
1943 ((eq (car what) 'server) ; server
1944 (setq sql-server
1945 (read-from-minibuffer "Server: " sql-server nil nil
1946 sql-server-history)))
1947 ((eq (car what) 'database) ; database
1948 (setq sql-database
1949 (read-from-minibuffer "Database: " sql-database nil nil
1950 sql-database-history))))
1951 (setq what (cdr what))))
1952
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))
1960 default-buffer
1961 (save-excursion
1962 (let ((buflist (buffer-list))
1963 (found))
1964 (while (not (or (null buflist)
1965 found))
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))))
1972 found)))))
1973
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."
1981 (interactive)
1982 (save-excursion
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)))
1991 (progn
1992 (setq sql-buffer default-sqli-buffer)
1993 (run-hooks 'sql-set-sqli-hook))))
1994 (setq buflist (cdr buflist))))))
1995
1996 (defun sql-set-sqli-buffer ()
1997 "Set the SQLi buffer SQL strings are sent to.
1998
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'.
2002
2003 If you call it from a SQL buffer, this sets the local copy of
2004 `sql-buffer'.
2005
2006 If you call it from anywhere else, it sets the global copy of
2007 `sql-buffer'."
2008 (interactive)
2009 (let ((default-buffer (sql-find-sqli-buffer)))
2010 (if (null default-buffer)
2011 (error "There is no suitable SQLi buffer"))
2012 (let ((new-buffer
2013 (get-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)))
2021 (if new-buffer
2022 (progn
2023 (setq sql-buffer new-buffer)
2024 (run-hooks 'sql-set-sqli-hook))))))
2025
2026 (defun sql-show-sqli-buffer ()
2027 "Show the name of current SQLi buffer.
2028
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."
2031 (interactive)
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)))))
2037
2038 (defun sql-make-alternate-buffer-name ()
2039 "Return a string that can be used to rename a SQLi buffer.
2040
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))
2045 ()
2046 (concat (user-login-name) "/"))
2047 (concat sql-user "/"))
2048 (if (string= "" sql-database)
2049 (if (string= "" sql-server)
2050 (system-name)
2051 sql-server)
2052 sql-database)))
2053
2054 (defun sql-rename-buffer ()
2055 "Renames a SQLi buffer."
2056 (interactive)
2057 (rename-buffer (format "*SQL: %s*" sql-alternate-buffer-name) t))
2058
2059 (defun sql-copy-column ()
2060 "Copy current column to the end of buffer.
2061 Inserts SELECT or commas if appropriate."
2062 (interactive)
2063 (let ((column))
2064 (save-excursion
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)))
2070 (cond
2071 ;; if empty command line, insert SELECT
2072 ((= bol (point))
2073 (insert "SELECT "))
2074 ;; else if appending to INTO .* (, SELECT or ORDER BY, insert a comma
2075 ((save-excursion
2076 (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+"
2077 bol t))
2078 (insert ", "))
2079 ;; else insert a space
2080 (t
2081 (if (eq (preceding-char) ?\s)
2082 nil
2083 (insert " ")))))
2084 ;; in any case, insert the column
2085 (insert column)
2086 (message "%s" column))))
2087
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.
2092
2093 (defvar sql-placeholder-history nil
2094 "History of placeholder values used.")
2095
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)
2105 t t string)))
2106 (comint-send-string proc string)
2107 (if comint-input-sender-no-newline
2108 (if (not (string-equal string ""))
2109 (process-send-eof))
2110 (comint-send-string proc "\n")))
2111
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)
2120 me (match-end 0))
2121 (if (and (> mb 1)
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")))
2125 (setq start me))
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 ""))
2130 (process-send-eof))
2131 (comint-send-string proc "\n"))))
2132
2133 \f
2134
2135 ;;; Sending the region to the SQLi buffer.
2136
2137 (defun sql-send-region (start end)
2138 "Send a region to the SQL process."
2139 (interactive "r")
2140 (if (buffer-live-p sql-buffer)
2141 (save-excursion
2142 (comint-send-region sql-buffer start end)
2143 (if (string-match "\n$" (buffer-substring start end))
2144 ()
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.")))
2151
2152 (defun sql-send-paragraph ()
2153 "Send the current paragraph to the SQL process."
2154 (interactive)
2155 (let ((start (save-excursion
2156 (backward-paragraph)
2157 (point)))
2158 (end (save-excursion
2159 (forward-paragraph)
2160 (point))))
2161 (sql-send-region start end)))
2162
2163 (defun sql-send-buffer ()
2164 "Send the buffer contents to the SQL process."
2165 (interactive)
2166 (sql-send-region (point-min) (point-max)))
2167
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)
2172 (save-excursion
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.")))
2180
2181 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value)
2182 "Toggle `sql-pop-to-buffer-after-send-region'.
2183
2184 If given the optional parameter VALUE, sets
2185 sql-toggle-pop-to-buffer-after-send-region to VALUE."
2186 (interactive "P")
2187 (if 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 ))))
2191
2192 \f
2193
2194 ;;; SQL mode -- uses SQL interactive mode
2195
2196 ;;;###autoload
2197 (defun sql-mode ()
2198 "Major mode to edit SQL.
2199
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.
2203
2204 \\{sql-mode-map}
2205 Customization: Entry to this mode runs the `sql-mode-hook'.
2206
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].
2213
2214 For information on how to create multiple SQLi buffers, see
2215 `sql-interactive-mode'.
2216
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:
2220
2221 \(add-hook 'sql-mode-hook
2222 (lambda ()
2223 (modify-syntax-entry ?\\\\ \".\" sql-mode-syntax-table)))"
2224 (interactive)
2225 (kill-all-local-variables)
2226 (setq major-mode 'sql-mode)
2227 (setq mode-name "SQL")
2228 (use-local-map sql-mode-map)
2229 (if sql-mode-menu
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
2244 ;; lines.
2245 (make-local-variable 'paragraph-separate)
2246 (make-local-variable 'paragraph-start)
2247 (setq paragraph-separate "[\f]*$"
2248 paragraph-start "[\n\f]")
2249 ;; Abbrevs
2250 (setq local-abbrev-table sql-mode-abbrev-table)
2251 (setq abbrev-all-caps 1)
2252 ;; Run hook
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))
2257
2258 \f
2259
2260 ;;; SQL interactive mode
2261
2262 (put 'sql-interactive-mode 'mode-class 'special)
2263
2264 (defun sql-interactive-mode ()
2265 "Major mode to use a SQL interpreter interactively.
2266
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.
2270
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.
2277
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.
2284
2285 Sample session using two connections:
2286
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\".
2293
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*\".
2297
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.
2301
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
2307 run.
2308
2309 Variable `sql-input-ring-file-name' controls the initialisation of the
2310 input ring history.
2311
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.
2316
2317 If you want to make SQL buffers limited in length, add the function
2318 `comint-truncate-buffer' to `comint-output-filter-functions'.
2319
2320 Here is an example for your .emacs file. It keeps the SQLi buffer a
2321 certain length.
2322
2323 \(add-hook 'sql-interactive-mode-hook
2324 \(function (lambda ()
2325 \(setq comint-output-filter-functions 'comint-truncate-buffer))))
2326
2327 Here is another example. It will always put point back to the statement
2328 you entered, right above the output it created.
2329
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
2336 sql-product))
2337 ;; Setup the mode.
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
2355 ;; by default.
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)
2370 ;; Run hook.
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))
2383
2384 (defun sql-stop (process event)
2385 "Called when the SQL process is stopped.
2386
2387 Writes the input history to a history file using
2388 `comint-write-input-ring' and inserts a short message in the SQL buffer.
2389
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)))
2397
2398 \f
2399
2400 ;;; Entry functions for different SQL interpreters.
2401
2402 ;;;###autoload
2403 (defun sql-product-interactive (&optional product)
2404 "Run product interpreter as an inferior process.
2405
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
2408 `*SQL*'.
2409
2410 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2411 (interactive)
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*")
2416 ;; Get credentials.
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))
2421 ;; Set SQLi mode.
2422 (setq sql-interactive-product product)
2423 (setq sql-buffer (current-buffer))
2424 (sql-interactive-mode)
2425 ;; All done.
2426 (message "Login...done")
2427 (pop-to-buffer sql-buffer))))
2428
2429 ;;;###autoload
2430 (defun sql-oracle ()
2431 "Run sqlplus by Oracle as an inferior process.
2432
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
2435 `*SQL*'.
2436
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'.
2441
2442 The buffer is put in sql-interactive-mode, giving commands for sending
2443 input. See `sql-interactive-mode'.
2444
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'.
2451
2452 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2453 (interactive)
2454 (sql-product-interactive 'oracle))
2455
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
2462 ;; "param".
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)))
2470 (if parameter
2471 (setq parameter (nconc (list parameter) sql-oracle-options))
2472 (setq parameter sql-oracle-options))
2473 (if parameter
2474 (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil
2475 parameter))
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))))
2480
2481 \f
2482
2483 ;;;###autoload
2484 (defun sql-sybase ()
2485 "Run isql by SyBase as an inferior process.
2486
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
2489 `*SQL*'.
2490
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'.
2495
2496 The buffer is put in sql-interactive-mode, giving commands for sending
2497 input. See `sql-interactive-mode'.
2498
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'.
2505
2506 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2507 (interactive)
2508 (sql-product-interactive 'sybase))
2509
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
2514 ;; make-comint.
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
2525 nil params))))
2526
2527 \f
2528
2529 ;;;###autoload
2530 (defun sql-informix ()
2531 "Run dbaccess by Informix as an inferior process.
2532
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
2535 `*SQL*'.
2536
2537 Interpreter used comes from variable `sql-informix-program'. Login uses
2538 the variable `sql-database' as default, if set.
2539
2540 The buffer is put in sql-interactive-mode, giving commands for sending
2541 input. See `sql-interactive-mode'.
2542
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'.
2549
2550 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2551 (interactive)
2552 (sql-product-interactive 'informix))
2553
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 "-"))))
2561
2562 \f
2563
2564 ;;;###autoload
2565 (defun sql-sqlite ()
2566 "Run sqlite as an inferior process.
2567
2568 SQLite is free software.
2569
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
2572 `*SQL*'.
2573
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'.
2578
2579 The buffer is put in sql-interactive-mode, giving commands for sending
2580 input. See `sql-interactive-mode'.
2581
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'.
2588
2589 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2590 (interactive)
2591 (sql-product-interactive 'sqlite))
2592
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
2597 ;; make-comint.
2598 (let ((params))
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
2610 nil params))))
2611
2612 \f
2613
2614 ;;;###autoload
2615 (defun sql-mysql ()
2616 "Run mysql by TcX as an inferior process.
2617
2618 Mysql versions 3.23 and up are free software.
2619
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
2622 `*SQL*'.
2623
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'.
2628
2629 The buffer is put in sql-interactive-mode, giving commands for sending
2630 input. See `sql-interactive-mode'.
2631
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'.
2638
2639 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2640 (interactive)
2641 (sql-product-interactive 'mysql))
2642
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
2647 ;; make-comint.
2648 (let ((params))
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
2660 nil params))))
2661
2662 \f
2663
2664 ;;;###autoload
2665 (defun sql-solid ()
2666 "Run solsql by Solid as an inferior process.
2667
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
2670 `*SQL*'.
2671
2672 Interpreter used comes from variable `sql-solid-program'. Login uses
2673 the variables `sql-user', `sql-password', and `sql-server' as
2674 defaults, if set.
2675
2676 The buffer is put in sql-interactive-mode, giving commands for sending
2677 input. See `sql-interactive-mode'.
2678
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'.
2685
2686 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2687 (interactive)
2688 (sql-product-interactive 'solid))
2689
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
2694 ;; make-comint.
2695 (let ((params))
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
2703 nil params))))
2704
2705 \f
2706
2707 ;;;###autoload
2708 (defun sql-ingres ()
2709 "Run sql by Ingres as an inferior process.
2710
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
2713 `*SQL*'.
2714
2715 Interpreter used comes from variable `sql-ingres-program'. Login uses
2716 the variable `sql-database' as default, if set.
2717
2718 The buffer is put in sql-interactive-mode, giving commands for sending
2719 input. See `sql-interactive-mode'.
2720
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'.
2727
2728 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2729 (interactive)
2730 (sql-product-interactive 'ingres))
2731
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))))
2739
2740 \f
2741
2742 ;;;###autoload
2743 (defun sql-ms ()
2744 "Run osql by Microsoft as an inferior process.
2745
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
2748 `*SQL*'.
2749
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'.
2754
2755 The buffer is put in sql-interactive-mode, giving commands for sending
2756 input. See `sql-interactive-mode'.
2757
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'.
2764
2765 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2766 (interactive)
2767 (sql-product-interactive 'ms))
2768
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
2773 ;; make-comint.
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
2785 ;; credentials.
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
2791 nil params))))
2792
2793 \f
2794
2795 ;;;###autoload
2796 (defun sql-postgres ()
2797 "Run psql by Postgres as an inferior process.
2798
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
2801 `*SQL*'.
2802
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'.
2807
2808 The buffer is put in sql-interactive-mode, giving commands for sending
2809 input. See `sql-interactive-mode'.
2810
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:
2819
2820 \(setq comint-output-filter-functions (append comint-output-filter-functions
2821 '(comint-strip-ctrl-m)))
2822
2823 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2824 (interactive)
2825 (sql-product-interactive 'postgres))
2826
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
2843 nil params))))
2844
2845 \f
2846
2847 ;;;###autoload
2848 (defun sql-interbase ()
2849 "Run isql by Interbase as an inferior process.
2850
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
2853 `*SQL*'.
2854
2855 Interpreter used comes from variable `sql-interbase-program'. Login
2856 uses the variables `sql-user', `sql-password', and `sql-database' as
2857 defaults, if set.
2858
2859 The buffer is put in sql-interactive-mode, giving commands for sending
2860 input. See `sql-interactive-mode'.
2861
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'.
2868
2869 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2870 (interactive)
2871 (sql-product-interactive 'interbase))
2872
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
2877 ;; make-comint.
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
2886 nil params))))
2887
2888 \f
2889
2890 ;;;###autoload
2891 (defun sql-db2 ()
2892 "Run db2 by IBM as an inferior process.
2893
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
2896 `*SQL*'.
2897
2898 Interpreter used comes from variable `sql-db2-program'. There is not
2899 automatic login.
2900
2901 The buffer is put in sql-interactive-mode, giving commands for sending
2902 input. See `sql-interactive-mode'.
2903
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.
2908
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'.
2915
2916 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2917 (interactive)
2918 (sql-product-interactive 'db2))
2919
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
2924 ;; make-comint.
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))
2929
2930 ;;;###autoload
2931 (defun sql-linter ()
2932 "Run inl by RELEX as an inferior process.
2933
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
2936 `*SQL*'.
2937
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
2942 parameters.
2943
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
2948 an empty password.
2949
2950 The buffer is put in sql-interactive-mode, giving commands for sending
2951 input. See `sql-interactive-mode'.
2952
2953 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2954 (interactive)
2955 (sql-product-interactive 'linter))
2956
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
2961 ;; make-comint.
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
2972 params))
2973 (setenv "LINTER_MBX" old-mbx)))
2974
2975 \f
2976
2977 (provide 'sql)
2978
2979 ;;; arch-tag: 7e1fa1c4-9ca2-402e-87d2-83a5eccb7ac3
2980 ;;; sql.el ends here