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