Commit | Line | Data |
---|---|---|
95e4b2ef RS |
1 | ;;; sql.el --- specialized comint.el for SQL interpreters |
2 | ||
ae940284 | 3 | ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
114f9c96 | 4 | ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
95e4b2ef | 5 | |
1533eb58 | 6 | ;; Author: Alex Schroeder <alex@gnu.org> |
dc45d1a6 | 7 | ;; Maintainer: Michael Mauger <mmaug@yahoo.com> |
74790210 | 8 | ;; Version: 2.8 |
dab100d7 | 9 | ;; Keywords: comm languages processes |
e084bc3d | 10 | ;; URL: http://savannah.gnu.org/projects/emacs/ |
aa88e662 | 11 | ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode |
95e4b2ef RS |
12 | |
13 | ;; This file is part of GNU Emacs. | |
14 | ||
b1fc2b50 | 15 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
95e4b2ef | 16 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
17 | ;; the Free Software Foundation, either version 3 of the License, or |
18 | ;; (at your option) any later version. | |
95e4b2ef RS |
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 | |
b1fc2b50 | 26 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
95e4b2ef RS |
27 | |
28 | ;;; Commentary: | |
29 | ||
c04bb32e | 30 | ;; Please send bug reports and bug fixes to the mailing list at |
01295a22 RS |
31 | ;; help-gnu-emacs@gnu.org. If you want to subscribe to the mailing |
32 | ;; list, see the web page at | |
33 | ;; http://lists.gnu.org/mailman/listinfo/help-gnu-emacs for | |
34 | ;; instructions. I monitor this list actively. If you send an e-mail | |
35 | ;; to Alex Schroeder it usually makes it to me when Alex has a chance | |
36 | ;; to forward them along (Thanks, Alex). | |
37 | ||
38 | ;; This file provides a sql-mode and a sql-interactive-mode. The | |
39 | ;; original goals were two simple modes providing syntactic | |
40 | ;; highlighting. The interactive mode had to provide a command-line | |
41 | ;; history; the other mode had to provide "send region/buffer to SQL | |
42 | ;; interpreter" functions. "simple" in this context means easy to | |
43 | ;; use, easy to maintain and little or no bells and whistles. This | |
44 | ;; has changed somewhat as experience with the mode has accumulated. | |
45 | ||
46 | ;; Support for different flavors of SQL and command interpreters was | |
47 | ;; available in early versions of sql.el. This support has been | |
48 | ;; extended and formalized in later versions. Part of the impetus for | |
49 | ;; the improved support of SQL flavors was borne out of the current | |
50 | ;; maintainer's consulting experience. In the past fifteen years, I | |
51 | ;; have used Oracle, Sybase, Informix, MySQL, Postgres, and SQLServer. | |
52 | ;; On some assignments, I have used two or more of these concurrently. | |
95e4b2ef RS |
53 | |
54 | ;; If anybody feels like extending this sql mode, take a look at the | |
55 | ;; above mentioned modes and write a sqlx-mode on top of this one. If | |
56 | ;; this proves to be difficult, please suggest changes that will | |
01295a22 RS |
57 | ;; facilitate your plans. Facilities have been provided to add |
58 | ;; products and product-specific configuration. | |
95e4b2ef RS |
59 | |
60 | ;; sql-interactive-mode is used to interact with a SQL interpreter | |
dab100d7 | 61 | ;; process in a SQLi buffer (usually called `*SQL*'). The SQLi buffer |
01295a22 RS |
62 | ;; is created by calling a SQL interpreter-specific entry function or |
63 | ;; sql-product-interactive. Do *not* call sql-interactive-mode by | |
64 | ;; itself. | |
95e4b2ef RS |
65 | |
66 | ;; The list of currently supported interpreters and the corresponding | |
dab100d7 | 67 | ;; entry function used to create the SQLi buffers is shown with |
95e4b2ef RS |
68 | ;; `sql-help' (M-x sql-help). |
69 | ||
70 | ;; Since sql-interactive-mode is built on top of the general | |
71 | ;; command-interpreter-in-a-buffer mode (comint mode), it shares a | |
72 | ;; common base functionality, and a common set of bindings, with all | |
73 | ;; modes derived from comint mode. This makes these modes easier to | |
74 | ;; use. | |
75 | ||
311e7a89 GM |
76 | ;; sql-mode can be used to keep editing SQL statements. The SQL |
77 | ;; statements can be sent to the SQL process in the SQLi buffer. | |
95e4b2ef RS |
78 | |
79 | ;; For documentation on the functionality provided by comint mode, and | |
eb3f61dd | 80 | ;; the hooks available for customizing it, see the file `comint.el'. |
95e4b2ef | 81 | |
801d1cb0 AS |
82 | ;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and |
83 | ;; `imenu-add-menubar-index'. | |
95e4b2ef RS |
84 | |
85 | ;;; Requirements for Emacs 19.34: | |
86 | ||
87 | ;; If you are using Emacs 19.34, you will have to get and install | |
88 | ;; the file regexp-opt.el | |
89 | ;; <URL:ftp://ftp.ifi.uio.no/pub/emacs/emacs-20.3/lisp/emacs-lisp/regexp-opt.el> | |
90 | ;; and the custom package | |
91 | ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>. | |
92 | ||
93 | ;;; Bugs: | |
94 | ||
78024f88 AS |
95 | ;; sql-ms now uses osql instead of isql. Osql flushes its error |
96 | ;; stream more frequently than isql so that error messages are | |
97 | ;; available. There is no prompt and some output still is buffered. | |
98 | ;; This improves the interaction under Emacs but it still is somewhat | |
99 | ;; awkward. | |
100 | ||
101 | ;; Quoted identifiers are not supported for hilighting. Most | |
102 | ;; databases support the use of double quoted strings in place of | |
103 | ;; identifiers; ms (Microsoft SQLServer) also supports identifiers | |
104 | ;; enclosed within brackets []. | |
95e4b2ef | 105 | |
78024f88 AS |
106 | ;;; Product Support: |
107 | ||
108 | ;; To add support for additional SQL products the following steps | |
109 | ;; must be followed ("xyz" is the name of the product in the examples | |
110 | ;; below): | |
111 | ||
7492acc9 | 112 | ;; 1) Add the product to the list of known products. |
78024f88 | 113 | |
7492acc9 MM |
114 | ;; (sql-add-product 'xyz "XyzDB" |
115 | ;; '(:free-software t)) | |
78024f88 | 116 | |
7492acc9 MM |
117 | ;; 2) Define font lock settings. All ANSI keywords will be |
118 | ;; highlighted automatically, so only product specific keywords | |
119 | ;; need to be defined here. | |
78024f88 | 120 | |
7492acc9 MM |
121 | ;; (defvar my-sql-mode-xyz-font-lock-keywords |
122 | ;; '(("\\b\\(red\\|orange\\|yellow\\)\\b" | |
123 | ;; . font-lock-keyword-face)) | |
124 | ;; "XyzDB SQL keywords used by font-lock.") | |
78024f88 | 125 | |
7492acc9 MM |
126 | ;; (sql-set-product-feature 'xyz |
127 | ;; :font-lock | |
128 | ;; 'my-sql-mode-xyz-font-lock-keywords) | |
78024f88 | 129 | |
7492acc9 MM |
130 | ;; 3) Define any special syntax characters including comments and |
131 | ;; identifier characters. | |
132 | ||
133 | ;; (sql-set-product-feature 'xyz | |
134 | ;; :syntax-alist ((?# . "w"))) | |
135 | ||
136 | ;; 4) Define the interactive command interpreter for the database | |
137 | ;; product. | |
138 | ||
139 | ;; (defcustom my-sql-xyz-program "ixyz" | |
140 | ;; "Command to start ixyz by XyzDB." | |
78024f88 AS |
141 | ;; :type 'file |
142 | ;; :group 'SQL) | |
143 | ;; | |
7492acc9 MM |
144 | ;; (sql-set-product-feature 'xyz |
145 | ;; :sqli-program 'my-sql-xyz-program) | |
146 | ;; (sql-set-product-feature 'xyz | |
147 | ;; :prompt-regexp "^xyzdb> ") | |
148 | ;; (sql-set-product-feature 'xyz | |
149 | ;; :prompt-length 7) | |
150 | ||
151 | ;; 5) Define login parameters and command line formatting. | |
152 | ||
153 | ;; (defcustom my-sql-xyz-login-params '(user password server database) | |
154 | ;; "Login parameters to needed to connect to XyzDB." | |
5474c40f | 155 | ;; :type 'sql-login-params |
78024f88 | 156 | ;; :group 'SQL) |
7492acc9 MM |
157 | ;; |
158 | ;; (sql-set-product-feature 'xyz | |
159 | ;; :sqli-login 'my-sql-xyz-login-params) | |
78024f88 | 160 | |
7492acc9 MM |
161 | ;; (defcustom my-sql-xyz-options '("-X" "-Y" "-Z") |
162 | ;; "List of additional options for `sql-xyz-program'." | |
163 | ;; :type '(repeat string) | |
164 | ;; :group 'SQL) | |
165 | ;; | |
166 | ;; (sql-set-product-feature 'xyz | |
167 | ;; :sqli-options 'my-sql-xyz-options)) | |
78024f88 | 168 | |
30c4d8dc | 169 | ;; (defun my-sql-comint-xyz (product options) |
7492acc9 | 170 | ;; "Connect ti XyzDB in a comint buffer." |
78024f88 AS |
171 | ;; |
172 | ;; ;; Do something with `sql-user', `sql-password', | |
173 | ;; ;; `sql-database', and `sql-server'. | |
7492acc9 | 174 | ;; (let ((params options)) |
78024f88 AS |
175 | ;; (if (not (string= "" sql-server)) |
176 | ;; (setq params (append (list "-S" sql-server) params))) | |
177 | ;; (if (not (string= "" sql-database)) | |
178 | ;; (setq params (append (list "-D" sql-database) params))) | |
179 | ;; (if (not (string= "" sql-password)) | |
180 | ;; (setq params (append (list "-P" sql-password) params))) | |
181 | ;; (if (not (string= "" sql-user)) | |
182 | ;; (setq params (append (list "-U" sql-user) params))) | |
30c4d8dc | 183 | ;; (sql-comint product params))) |
7492acc9 MM |
184 | ;; |
185 | ;; (sql-set-product-feature 'xyz | |
d26b0ea9 | 186 | ;; :sqli-comint-func 'my-sql-comint-xyz) |
78024f88 | 187 | |
7492acc9 MM |
188 | ;; 6) Define a convienence function to invoke the SQL interpreter. |
189 | ||
9250002f | 190 | ;; (defun my-sql-xyz (&optional buffer) |
7492acc9 | 191 | ;; "Run ixyz by XyzDB as an inferior process." |
9250002f MM |
192 | ;; (interactive "P") |
193 | ;; (sql-product-interactive 'xyz buffer)) | |
78024f88 | 194 | |
b4dd5c9c JB |
195 | ;;; To Do: |
196 | ||
7492acc9 MM |
197 | ;; Improve keyword highlighting for individual products. I have tried |
198 | ;; to update those database that I use. Feel free to send me updates, | |
199 | ;; or direct me to the reference manuals for your favorite database. | |
b4dd5c9c | 200 | |
7492acc9 MM |
201 | ;; When there are no keywords defined, the ANSI keywords are |
202 | ;; highlighted. ANSI keywords are highlighted even if the keyword is | |
203 | ;; not used for your current product. This should help identify | |
204 | ;; portability concerns. | |
205 | ||
206 | ;; Add different highlighting levels. | |
207 | ||
208 | ;; Add support for listing available tables or the columns in a table. | |
95e4b2ef RS |
209 | |
210 | ;;; Thanks to all the people who helped me out: | |
211 | ||
7492acc9 | 212 | ;; Alex Schroeder <alex@gnu.org> -- the original author |
95e4b2ef RS |
213 | ;; Kai Blauberg <kai.blauberg@metla.fi> |
214 | ;; <ibalaban@dalet.com> | |
215 | ;; Yair Friedman <yfriedma@JohnBryce.Co.Il> | |
216 | ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> | |
a081a529 | 217 | ;; nino <nino@inform.dk> |
801d1cb0 | 218 | ;; Berend de Boer <berend@pobox.com> |
9fd8cb36 | 219 | ;; Adam Jenkins <adam@thejenkins.org> |
9a9069c9 SM |
220 | ;; Michael Mauger <mmaug@yahoo.com> -- improved product support |
221 | ;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support | |
222 | ;; Harald Maier <maierh@myself.com> -- sql-send-string | |
7492acc9 | 223 | ;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections; code polish |
dab100d7 | 224 | |
95e4b2ef RS |
225 | \f |
226 | ||
227 | ;;; Code: | |
228 | ||
229 | (require 'comint) | |
230 | ;; Need the following to allow GNU Emacs 19 to compile the file. | |
78024f88 AS |
231 | (eval-when-compile |
232 | (require 'regexp-opt)) | |
95e4b2ef | 233 | (require 'custom) |
9fd8cb36 | 234 | (eval-when-compile ;; needed in Emacs 19, 20 |
d26b0ea9 | 235 | (setq max-specpdl-size (max max-specpdl-size 2000))) |
95e4b2ef | 236 | |
ec38bb46 JB |
237 | (defvar font-lock-keyword-face) |
238 | (defvar font-lock-set-defaults) | |
239 | (defvar font-lock-string-face) | |
240 | ||
95e4b2ef RS |
241 | ;;; Allow customization |
242 | ||
243 | (defgroup SQL nil | |
b9584f65 | 244 | "Running a SQL interpreter from within Emacs buffers." |
6629e5ba | 245 | :version "20.4" |
7492acc9 | 246 | :group 'languages |
95e4b2ef RS |
247 | :group 'processes) |
248 | ||
78024f88 | 249 | ;; These four variables will be used as defaults, if set. |
95e4b2ef RS |
250 | |
251 | (defcustom sql-user "" | |
7492acc9 | 252 | "Default username." |
95e4b2ef | 253 | :type 'string |
30c4d8dc MM |
254 | :group 'SQL |
255 | :safe 'stringp) | |
95e4b2ef RS |
256 | |
257 | (defcustom sql-password "" | |
7492acc9 | 258 | "Default password. |
95e4b2ef RS |
259 | |
260 | Storing your password in a textfile such as ~/.emacs could be dangerous. | |
261 | Customizing your password will store it in your ~/.emacs file." | |
262 | :type 'string | |
30c4d8dc MM |
263 | :group 'SQL |
264 | :risky t) | |
95e4b2ef RS |
265 | |
266 | (defcustom sql-database "" | |
7492acc9 | 267 | "Default database." |
95e4b2ef | 268 | :type 'string |
30c4d8dc MM |
269 | :group 'SQL |
270 | :safe 'stringp) | |
95e4b2ef RS |
271 | |
272 | (defcustom sql-server "" | |
7492acc9 | 273 | "Default server or host." |
95e4b2ef | 274 | :type 'string |
30c4d8dc MM |
275 | :group 'SQL |
276 | :safe 'stringp) | |
7492acc9 | 277 | |
9250002f MM |
278 | (defcustom sql-port 0 |
279 | "Default port." | |
30c4d8dc | 280 | :version "24.1" |
7492acc9 | 281 | :type 'number |
30c4d8dc MM |
282 | :group 'SQL |
283 | :safe 'numberp) | |
95e4b2ef | 284 | |
5474c40f MM |
285 | ;; Login parameter type |
286 | ||
287 | (define-widget 'sql-login-params 'lazy | |
288 | "Widget definition of the login parameters list" | |
74790210 MM |
289 | ;; FIXME: does not implement :default property for the user, |
290 | ;; database and server options. Anybody have some guidance on how to | |
291 | ;; do this. | |
5474c40f MM |
292 | :tag "Login Parameters" |
293 | :type '(repeat (choice | |
294 | (const user) | |
295 | (const password) | |
296 | (choice :tag "server" | |
297 | (const server) | |
298 | (list :tag "file" | |
299 | (const :format "" server) | |
300 | (const :format "" :file) | |
301 | regexp) | |
302 | (list :tag "completion" | |
303 | (const :format "" server) | |
304 | (const :format "" :completion) | |
305 | (restricted-sexp | |
74790210 | 306 | :match-alternatives (listp stringp)))) |
5474c40f MM |
307 | (choice :tag "database" |
308 | (const database) | |
309 | (list :tag "file" | |
310 | (const :format "" database) | |
311 | (const :format "" :file) | |
312 | regexp) | |
313 | (list :tag "completion" | |
314 | (const :format "" database) | |
315 | (const :format "" :completion) | |
316 | (restricted-sexp | |
74790210 | 317 | :match-alternatives (listp stringp)))) |
5474c40f MM |
318 | (const port)))) |
319 | ||
78024f88 | 320 | ;; SQL Product support |
78024f88 AS |
321 | |
322 | (defvar sql-interactive-product nil | |
323 | "Product under `sql-interactive-mode'.") | |
324 | ||
30c4d8dc MM |
325 | (defvar sql-connection nil |
326 | "Connection name if interactive session started by `sql-connect'.") | |
327 | ||
9fd8cb36 | 328 | (defvar sql-product-alist |
78024f88 | 329 | '((ansi |
55659495 | 330 | :name "ANSI" |
78024f88 | 331 | :font-lock sql-mode-ansi-font-lock-keywords) |
7492acc9 | 332 | |
78024f88 | 333 | (db2 |
55659495 | 334 | :name "DB2" |
78024f88 | 335 | :font-lock sql-mode-db2-font-lock-keywords |
7492acc9 MM |
336 | :sqli-program sql-db2-program |
337 | :sqli-options sql-db2-options | |
338 | :sqli-login sql-db2-login-params | |
30c4d8dc | 339 | :sqli-comint-func sql-comint-db2 |
7492acc9 MM |
340 | :prompt-regexp "^db2 => " |
341 | :prompt-length 7 | |
3bd2cfef | 342 | :prompt-cont-regexp "^db2 (cont\.) => " |
7492acc9 MM |
343 | :input-filter sql-escape-newlines-filter) |
344 | ||
78024f88 | 345 | (informix |
7492acc9 | 346 | :name "Informix" |
78024f88 | 347 | :font-lock sql-mode-informix-font-lock-keywords |
7492acc9 MM |
348 | :sqli-program sql-informix-program |
349 | :sqli-options sql-informix-options | |
350 | :sqli-login sql-informix-login-params | |
30c4d8dc | 351 | :sqli-comint-func sql-comint-informix |
7492acc9 MM |
352 | :prompt-regexp "^> " |
353 | :prompt-length 2 | |
354 | :syntax-alist ((?{ . "<") (?} . ">"))) | |
355 | ||
78024f88 | 356 | (ingres |
7492acc9 | 357 | :name "Ingres" |
78024f88 | 358 | :font-lock sql-mode-ingres-font-lock-keywords |
7492acc9 MM |
359 | :sqli-program sql-ingres-program |
360 | :sqli-options sql-ingres-options | |
361 | :sqli-login sql-ingres-login-params | |
30c4d8dc | 362 | :sqli-comint-func sql-comint-ingres |
7492acc9 | 363 | :prompt-regexp "^\* " |
3bd2cfef MM |
364 | :prompt-length 2 |
365 | :prompt-cont-regexp "^\* ") | |
7492acc9 | 366 | |
78024f88 | 367 | (interbase |
7492acc9 | 368 | :name "Interbase" |
78024f88 | 369 | :font-lock sql-mode-interbase-font-lock-keywords |
7492acc9 MM |
370 | :sqli-program sql-interbase-program |
371 | :sqli-options sql-interbase-options | |
372 | :sqli-login sql-interbase-login-params | |
30c4d8dc | 373 | :sqli-comint-func sql-comint-interbase |
7492acc9 MM |
374 | :prompt-regexp "^SQL> " |
375 | :prompt-length 5) | |
376 | ||
78024f88 | 377 | (linter |
7492acc9 | 378 | :name "Linter" |
78024f88 | 379 | :font-lock sql-mode-linter-font-lock-keywords |
7492acc9 MM |
380 | :sqli-program sql-linter-program |
381 | :sqli-options sql-linter-options | |
382 | :sqli-login sql-linter-login-params | |
30c4d8dc | 383 | :sqli-comint-func sql-comint-linter |
7492acc9 MM |
384 | :prompt-regexp "^SQL>" |
385 | :prompt-length 4) | |
386 | ||
78024f88 | 387 | (ms |
7492acc9 | 388 | :name "Microsoft" |
78024f88 | 389 | :font-lock sql-mode-ms-font-lock-keywords |
7492acc9 MM |
390 | :sqli-program sql-ms-program |
391 | :sqli-options sql-ms-options | |
392 | :sqli-login sql-ms-login-params | |
30c4d8dc | 393 | :sqli-comint-func sql-comint-ms |
7492acc9 MM |
394 | :prompt-regexp "^[0-9]*>" |
395 | :prompt-length 5 | |
396 | :syntax-alist ((?@ . "w")) | |
397 | :terminator ("^go" . "go")) | |
398 | ||
78024f88 | 399 | (mysql |
55659495 | 400 | :name "MySQL" |
7492acc9 | 401 | :free-software t |
78024f88 | 402 | :font-lock sql-mode-mysql-font-lock-keywords |
7492acc9 MM |
403 | :sqli-program sql-mysql-program |
404 | :sqli-options sql-mysql-options | |
405 | :sqli-login sql-mysql-login-params | |
30c4d8dc | 406 | :sqli-comint-func sql-comint-mysql |
74790210 MM |
407 | :list-all "SHOW TABLES;" |
408 | :list-table "DESCRIBE %s;" | |
7492acc9 MM |
409 | :prompt-regexp "^mysql> " |
410 | :prompt-length 6 | |
3bd2cfef | 411 | :prompt-cont-regexp "^ -> " |
7492acc9 MM |
412 | :input-filter sql-remove-tabs-filter) |
413 | ||
78024f88 | 414 | (oracle |
7492acc9 | 415 | :name "Oracle" |
78024f88 | 416 | :font-lock sql-mode-oracle-font-lock-keywords |
7492acc9 MM |
417 | :sqli-program sql-oracle-program |
418 | :sqli-options sql-oracle-options | |
419 | :sqli-login sql-oracle-login-params | |
30c4d8dc | 420 | :sqli-comint-func sql-comint-oracle |
7492acc9 MM |
421 | :prompt-regexp "^SQL> " |
422 | :prompt-length 5 | |
3bd2cfef | 423 | :prompt-cont-regexp "^\\s-*\\d+> " |
7492acc9 MM |
424 | :syntax-alist ((?$ . "w") (?# . "w")) |
425 | :terminator ("\\(^/\\|;\\)" . "/") | |
426 | :input-filter sql-placeholders-filter) | |
427 | ||
78024f88 | 428 | (postgres |
7492acc9 MM |
429 | :name "Postgres" |
430 | :free-software t | |
78024f88 | 431 | :font-lock sql-mode-postgres-font-lock-keywords |
7492acc9 MM |
432 | :sqli-program sql-postgres-program |
433 | :sqli-options sql-postgres-options | |
434 | :sqli-login sql-postgres-login-params | |
30c4d8dc | 435 | :sqli-comint-func sql-comint-postgres |
74790210 MM |
436 | :list-all ("\\d+" . "\\dS+") |
437 | :list-table ("\\d+ %s" . "\\dS+ %s") | |
3bd2cfef | 438 | :prompt-regexp "^.*=[#>] " |
7492acc9 | 439 | :prompt-length 5 |
9250002f | 440 | :prompt-cont-regexp "^.*[-(][#>] " |
7492acc9 | 441 | :input-filter sql-remove-tabs-filter |
9250002f | 442 | :terminator ("\\(^\\s-*\\\\g\\|;\\)" . ";")) |
7492acc9 | 443 | |
78024f88 | 444 | (solid |
7492acc9 | 445 | :name "Solid" |
78024f88 | 446 | :font-lock sql-mode-solid-font-lock-keywords |
7492acc9 MM |
447 | :sqli-program sql-solid-program |
448 | :sqli-options sql-solid-options | |
449 | :sqli-login sql-solid-login-params | |
30c4d8dc | 450 | :sqli-comint-func sql-comint-solid |
7492acc9 MM |
451 | :prompt-regexp "^" |
452 | :prompt-length 0) | |
453 | ||
78024f88 | 454 | (sqlite |
55659495 | 455 | :name "SQLite" |
7492acc9 | 456 | :free-software t |
78024f88 | 457 | :font-lock sql-mode-sqlite-font-lock-keywords |
7492acc9 MM |
458 | :sqli-program sql-sqlite-program |
459 | :sqli-options sql-sqlite-options | |
460 | :sqli-login sql-sqlite-login-params | |
30c4d8dc | 461 | :sqli-comint-func sql-comint-sqlite |
74790210 MM |
462 | :list-all ".tables" |
463 | :list-table ".schema %s" | |
7492acc9 | 464 | :prompt-regexp "^sqlite> " |
3bd2cfef MM |
465 | :prompt-length 8 |
466 | :prompt-cont-regexp "^ ...> " | |
467 | :terminator ";") | |
7492acc9 | 468 | |
78024f88 | 469 | (sybase |
7492acc9 | 470 | :name "Sybase" |
78024f88 | 471 | :font-lock sql-mode-sybase-font-lock-keywords |
7492acc9 MM |
472 | :sqli-program sql-sybase-program |
473 | :sqli-options sql-sybase-options | |
474 | :sqli-login sql-sybase-login-params | |
30c4d8dc | 475 | :sqli-comint-func sql-comint-sybase |
7492acc9 MM |
476 | :prompt-regexp "^SQL> " |
477 | :prompt-length 5 | |
478 | :syntax-alist ((?@ . "w")) | |
479 | :terminator ("^go" . "go")) | |
78024f88 | 480 | ) |
7492acc9 MM |
481 | "An alist of product specific configuration settings. |
482 | ||
483 | Without an entry in this list a product will not be properly | |
484 | highlighted and will not support `sql-interactive-mode'. | |
78024f88 AS |
485 | |
486 | Each element in the list is in the following format: | |
487 | ||
488 | \(PRODUCT FEATURE VALUE ...) | |
489 | ||
7492acc9 MM |
490 | where PRODUCT is the appropriate value of `sql-product'. The |
491 | product name is then followed by FEATURE-VALUE pairs. If a | |
492 | FEATURE is not specified, its VALUE is treated as nil. FEATURE | |
493 | may be any one of the following: | |
494 | ||
495 | :name string containing the displayable name of | |
496 | the product. | |
497 | ||
498 | :free-software is the product Free (as in Freedom) software? | |
78024f88 AS |
499 | |
500 | :font-lock name of the variable containing the product | |
501 | specific font lock highlighting patterns. | |
502 | ||
7492acc9 MM |
503 | :sqli-program name of the variable containing the product |
504 | specific interactive program name. | |
505 | ||
506 | :sqli-options name of the variable containing the list | |
507 | of product specific options. | |
78024f88 | 508 | |
7492acc9 MM |
509 | :sqli-login name of the variable containing the list of |
510 | login parameters (i.e., user, password, | |
511 | database and server) needed to connect to | |
512 | the database. | |
513 | ||
30c4d8dc | 514 | :sqli-comint-func name of a function which accepts no |
78024f88 AS |
515 | parameters that will use the values of |
516 | `sql-user', `sql-password', | |
517 | `sql-database' and `sql-server' to open a | |
518 | comint buffer and connect to the | |
519 | database. Do product specific | |
520 | configuration of comint in this function. | |
521 | ||
74790210 MM |
522 | :list-all Command string or function which produces |
523 | a listing of all objects in the database. | |
524 | If it's a cons cell, then the car | |
525 | produces the standard list of objects and | |
526 | the cdr produces an enhanced list of | |
527 | objects. What \"enhanced\" means is | |
528 | dependent on the SQL product and may not | |
529 | exist. In general though, the | |
530 | \"enhanced\" list should include visible | |
531 | objects from other schemas. | |
532 | ||
533 | :list-table Command string or function which produces | |
534 | a detailed listing of a specific database | |
535 | table. If its a cons cell, then the car | |
536 | produces the standard list and the cdr | |
537 | produces an enhanced list. | |
538 | ||
7492acc9 | 539 | :prompt-regexp regular expression string that matches |
9fd8cb36 | 540 | the prompt issued by the product |
7492acc9 MM |
541 | interpreter. |
542 | ||
543 | :prompt-length length of the prompt on the line. | |
544 | ||
3bd2cfef MM |
545 | :prompt-cont-regexp regular expression string that matches |
546 | the continuation prompt issued by the | |
547 | product interpreter. | |
548 | ||
7492acc9 MM |
549 | :input-filter function which can filter strings sent to |
550 | the command interpreter. It is also used | |
551 | by the `sql-send-string', | |
552 | `sql-send-region', `sql-send-paragraph' | |
553 | and `sql-send-buffer' functions. The | |
554 | function is passed the string sent to the | |
555 | command interpreter and must return the | |
3bd2cfef MM |
556 | filtered string. May also be a list of |
557 | such functions. | |
7492acc9 MM |
558 | |
559 | :terminator the terminator to be sent after a | |
560 | `sql-send-string', `sql-send-region', | |
561 | `sql-send-paragraph' and | |
562 | `sql-send-buffer' command. May be the | |
563 | literal string or a cons of a regexp to | |
564 | match an existing terminator in the | |
565 | string and the terminator to be used if | |
566 | its absent. By default \";\". | |
567 | ||
568 | :syntax-alist alist of syntax table entries to enable | |
569 | special character treatment by font-lock | |
570 | and imenu. | |
571 | ||
572 | Other features can be stored but they will be ignored. However, | |
573 | you can develop new functionality which is product independent by | |
574 | using `sql-get-product-feature' to lookup the product specific | |
575 | settings.") | |
576 | ||
577 | (defvar sql-indirect-features | |
578 | '(:font-lock :sqli-program :sqli-options :sqli-login)) | |
78024f88 | 579 | |
30c4d8dc MM |
580 | (defcustom sql-connection-alist nil |
581 | "An alist of connection parameters for interacting with a SQL | |
582 | product. | |
583 | ||
584 | Each element of the alist is as follows: | |
585 | ||
586 | \(CONNECTION \(SQL-VARIABLE VALUE) ...) | |
587 | ||
588 | Where CONNECTION is a symbol identifying the connection, SQL-VARIABLE | |
589 | is the symbol name of a SQL mode variable, and VALUE is the value to | |
590 | be assigned to the variable. | |
591 | ||
592 | The most common SQL-VARIABLE settings associated with a connection | |
593 | are: | |
594 | ||
595 | `sql-product' | |
596 | `sql-user' | |
597 | `sql-password' | |
598 | `sql-port' | |
599 | `sql-server' | |
600 | `sql-database' | |
601 | ||
602 | If a SQL-VARIABLE is part of the connection, it will not be | |
603 | prompted for during login." | |
604 | ||
d26b0ea9 | 605 | :type `(alist :key-type (string :tag "Connection") |
30c4d8dc MM |
606 | :value-type |
607 | (set | |
608 | (group (const :tag "Product" sql-product) | |
609 | (choice | |
610 | ,@(mapcar (lambda (prod-info) | |
611 | `(const :tag | |
612 | ,(or (plist-get (cdr prod-info) :name) | |
613 | (capitalize (symbol-name (car prod-info)))) | |
614 | (quote ,(car prod-info)))) | |
615 | sql-product-alist))) | |
616 | (group (const :tag "Username" sql-user) string) | |
617 | (group (const :tag "Password" sql-password) string) | |
618 | (group (const :tag "Server" sql-server) string) | |
619 | (group (const :tag "Database" sql-database) string) | |
d26b0ea9 MM |
620 | (group (const :tag "Port" sql-port) integer) |
621 | (repeat :inline t | |
622 | (list :tab "Other" | |
623 | (symbol :tag " Variable Symbol") | |
624 | (sexp :tag "Value Expression"))))) | |
30c4d8dc MM |
625 | :version "24.1" |
626 | :group 'SQL) | |
627 | ||
55659495 | 628 | (defcustom sql-product 'ansi |
7492acc9 | 629 | "Select the SQL database product used so that buffers can be |
55659495 SM |
630 | highlighted properly when you open them." |
631 | :type `(choice | |
632 | ,@(mapcar (lambda (prod-info) | |
633 | `(const :tag | |
634 | ,(or (plist-get (cdr prod-info) :name) | |
635 | (capitalize (symbol-name (car prod-info)))) | |
636 | ,(car prod-info))) | |
637 | sql-product-alist)) | |
30c4d8dc MM |
638 | :group 'SQL |
639 | :safe 'symbolp) | |
9250002f | 640 | (defvaralias 'sql-dialect 'sql-product) |
7492acc9 MM |
641 | |
642 | ;; misc customization of sql.el behaviour | |
801d1cb0 | 643 | |
9ef3882f GM |
644 | (defcustom sql-electric-stuff nil |
645 | "Treat some input as electric. | |
646 | If set to the symbol `semicolon', then hitting `;' will send current | |
647 | input in the SQLi buffer to the process. | |
648 | If set to the symbol `go', then hitting `go' on a line by itself will | |
649 | send current input in the SQLi buffer to the process. | |
650 | If set to nil, then you must use \\[comint-send-input] in order to send | |
651 | current input in the SQLi buffer to the process." | |
652 | :type '(choice (const :tag "Nothing" nil) | |
063c6324 | 653 | (const :tag "The semicolon `;'" semicolon) |
9ef3882f GM |
654 | (const :tag "The string `go' by itself" go)) |
655 | :version "20.8" | |
656 | :group 'SQL) | |
657 | ||
7492acc9 MM |
658 | (defcustom sql-send-terminator nil |
659 | "When non-nil, add a terminator to text sent to the SQL interpreter. | |
660 | ||
661 | When text is sent to the SQL interpreter (via `sql-send-string', | |
662 | `sql-send-region', `sql-send-paragraph' or `sql-send-buffer'), a | |
663 | command terminator can be automatically sent as well. The | |
664 | terminator is not sent, if the string sent already ends with the | |
665 | terminator. | |
666 | ||
667 | If this value is t, then the default command terminator for the | |
668 | SQL interpreter is sent. If this value is a string, then the | |
669 | string is sent. | |
670 | ||
671 | If the value is a cons cell of the form (PAT . TERM), then PAT is | |
672 | a regexp used to match the terminator in the string and TERM is | |
673 | the terminator to be sent. This form is useful if the SQL | |
674 | interpreter has more than one way of submitting a SQL command. | |
675 | The PAT regexp can match any of them, and TERM is the way we do | |
676 | it automatically." | |
677 | ||
678 | :type '(choice (const :tag "No Terminator" nil) | |
679 | (const :tag "Default Terminator" t) | |
680 | (string :tag "Terminator String") | |
681 | (cons :tag "Terminator Pattern and String" | |
682 | (string :tag "Terminator Pattern") | |
683 | (string :tag "Terminator String"))) | |
684 | :version "22.2" | |
685 | :group 'SQL) | |
95e4b2ef | 686 | |
7492acc9 MM |
687 | (defcustom sql-pop-to-buffer-after-send-region nil |
688 | "When non-nil, pop to the buffer SQL statements are sent to. | |
689 | ||
690 | After a call to `sql-sent-string', `sql-send-region', | |
691 | `sql-send-paragraph' or `sql-send-buffer', the window is split | |
692 | and the SQLi buffer is shown. If this variable is not nil, that | |
693 | buffer's window will be selected by calling `pop-to-buffer'. If | |
694 | this variable is nil, that buffer is shown using | |
695 | `display-buffer'." | |
c7055d66 RS |
696 | :type 'boolean |
697 | :group 'SQL) | |
698 | ||
801d1cb0 AS |
699 | ;; imenu support for sql-mode. |
700 | ||
701 | (defvar sql-imenu-generic-expression | |
78024f88 | 702 | ;; Items are in reverse order because they are rendered in reverse. |
9fd8cb36 SM |
703 | '(("Rules/Defaults" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(rule\\|default\\)\\s-+\\(\\w+\\)" 3) |
704 | ("Sequences" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*sequence\\s-+\\(\\w+\\)" 2) | |
705 | ("Triggers" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*trigger\\s-+\\(\\w+\\)" 2) | |
706 | ("Functions" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?function\\s-+\\(\\w+\\)" 3) | |
707 | ("Procedures" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4) | |
708 | ("Packages" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3) | |
7492acc9 | 709 | ("Types" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*type\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3) |
9fd8cb36 SM |
710 | ("Indexes" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*index\\s-+\\(\\w+\\)" 2) |
711 | ("Tables/Views" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(table\\|view\\)\\s-+\\(\\w+\\)" 3)) | |
801d1cb0 AS |
712 | "Define interesting points in the SQL buffer for `imenu'. |
713 | ||
9ef3882f | 714 | This is used to set `imenu-generic-expression' when SQL mode is |
063c6324 JB |
715 | entered. Subsequent changes to `sql-imenu-generic-expression' will |
716 | not affect existing SQL buffers because imenu-generic-expression is | |
717 | a local variable.") | |
801d1cb0 AS |
718 | |
719 | ;; history file | |
720 | ||
c7055d66 | 721 | (defcustom sql-input-ring-file-name nil |
7492acc9 | 722 | "If non-nil, name of the file to read/write input history. |
c7055d66 | 723 | |
9ef73b91 KH |
724 | You have to set this variable if you want the history of your commands |
725 | saved from one Emacs session to the next. If this variable is set, | |
726 | exiting the SQL interpreter in an SQLi buffer will write the input | |
727 | history to the specified file. Starting a new process in a SQLi buffer | |
728 | will read the input history from the specified file. | |
729 | ||
77d352a6 GM |
730 | This is used to initialize `comint-input-ring-file-name'. |
731 | ||
732 | Note that the size of the input history is determined by the variable | |
733 | `comint-input-ring-size'." | |
c7055d66 RS |
734 | :type '(choice (const :tag "none" nil) |
735 | (file)) | |
736 | :group 'SQL) | |
737 | ||
738 | (defcustom sql-input-ring-separator "\n--\n" | |
7492acc9 | 739 | "Separator between commands in the history file. |
c7055d66 RS |
740 | |
741 | If set to \"\\n\", each line in the history file will be interpreted as | |
742 | one command. Multi-line commands are split into several commands when | |
743 | the input ring is initialized from a history file. | |
744 | ||
77d352a6 GM |
745 | This variable used to initialize `comint-input-ring-separator'. |
746 | `comint-input-ring-separator' is part of Emacs 21; if your Emacs | |
747 | does not have it, setting `sql-input-ring-separator' will have no | |
748 | effect. In that case multiline commands will be split into several | |
749 | commands when the input history is read, as if you had set | |
750 | `sql-input-ring-separator' to \"\\n\"." | |
95e4b2ef RS |
751 | :type 'string |
752 | :group 'SQL) | |
753 | ||
754 | ;; The usual hooks | |
755 | ||
756 | (defcustom sql-interactive-mode-hook '() | |
7492acc9 | 757 | "Hook for customizing `sql-interactive-mode'." |
95e4b2ef RS |
758 | :type 'hook |
759 | :group 'SQL) | |
760 | ||
761 | (defcustom sql-mode-hook '() | |
7492acc9 | 762 | "Hook for customizing `sql-mode'." |
95e4b2ef RS |
763 | :type 'hook |
764 | :group 'SQL) | |
765 | ||
c7055d66 | 766 | (defcustom sql-set-sqli-hook '() |
7492acc9 | 767 | "Hook for reacting to changes of `sql-buffer'. |
c7055d66 RS |
768 | |
769 | This is called by `sql-set-sqli-buffer' when the value of `sql-buffer' | |
770 | is changed." | |
771 | :type 'hook | |
772 | :group 'SQL) | |
773 | ||
eb3f61dd | 774 | ;; Customization for Oracle |
95e4b2ef RS |
775 | |
776 | (defcustom sql-oracle-program "sqlplus" | |
7492acc9 | 777 | "Command to start sqlplus by Oracle. |
95e4b2ef RS |
778 | |
779 | Starts `sql-interactive-mode' after doing some setup. | |
780 | ||
c38762fd JB |
781 | On Windows, \"sqlplus\" usually starts the sqlplus \"GUI\". In order |
782 | to start the sqlplus console, use \"plus33\" or something similar. | |
783 | You will find the file in your Orant\\bin directory." | |
a081a529 RS |
784 | :type 'file |
785 | :group 'SQL) | |
786 | ||
9ef3882f | 787 | (defcustom sql-oracle-options nil |
7492acc9 | 788 | "List of additional options for `sql-oracle-program'." |
9ef3882f GM |
789 | :type '(repeat string) |
790 | :version "20.8" | |
791 | :group 'SQL) | |
792 | ||
7492acc9 MM |
793 | (defcustom sql-oracle-login-params '(user password database) |
794 | "List of login parameters needed to connect to Oracle." | |
5474c40f | 795 | :type 'sql-login-params |
7492acc9 MM |
796 | :version "24.1" |
797 | :group 'SQL) | |
798 | ||
799 | (defcustom sql-oracle-scan-on t | |
800 | "Non-nil if placeholders should be replaced in Oracle SQLi. | |
801 | ||
802 | When non-nil, Emacs will scan text sent to sqlplus and prompt | |
803 | for replacement text for & placeholders as sqlplus does. This | |
c38762fd | 804 | is needed on Windows where sqlplus output is buffered and the |
7492acc9 MM |
805 | prompts are not shown until after the text is entered. |
806 | ||
807 | You will probably want to issue the following command in sqlplus | |
808 | to be safe: | |
809 | ||
810 | SET SCAN OFF" | |
811 | :type 'boolean | |
812 | :group 'SQL) | |
813 | ||
5d538ce3 JB |
814 | ;; Customization for SQLite |
815 | ||
9250002f MM |
816 | (defcustom sql-sqlite-program (or (executable-find "sqlite3") |
817 | (executable-find "sqlite") | |
818 | "sqlite") | |
7492acc9 | 819 | "Command to start SQLite. |
5d538ce3 | 820 | |
7492acc9 | 821 | Starts `sql-interactive-mode' after doing some setup." |
5d538ce3 JB |
822 | :type 'file |
823 | :group 'SQL) | |
824 | ||
825 | (defcustom sql-sqlite-options nil | |
7492acc9 | 826 | "List of additional options for `sql-sqlite-program'." |
5d538ce3 JB |
827 | :type '(repeat string) |
828 | :version "20.8" | |
829 | :group 'SQL) | |
830 | ||
9250002f | 831 | (defcustom sql-sqlite-login-params '((database :file ".*\\.\\(db\\|sqlite[23]?\\)")) |
7492acc9 | 832 | "List of login parameters needed to connect to SQLite." |
5474c40f | 833 | :type 'sql-login-params |
7492acc9 MM |
834 | :version "24.1" |
835 | :group 'SQL) | |
836 | ||
eb3f61dd | 837 | ;; Customization for MySql |
a081a529 RS |
838 | |
839 | (defcustom sql-mysql-program "mysql" | |
7492acc9 | 840 | "Command to start mysql by TcX. |
a081a529 | 841 | |
7492acc9 | 842 | Starts `sql-interactive-mode' after doing some setup." |
dab100d7 RS |
843 | :type 'file |
844 | :group 'SQL) | |
845 | ||
542c6552 | 846 | (defcustom sql-mysql-options nil |
7492acc9 | 847 | "List of additional options for `sql-mysql-program'. |
524c8caf GM |
848 | The following list of options is reported to make things work |
849 | on Windows: \"-C\" \"-t\" \"-f\" \"-n\"." | |
542c6552 GM |
850 | :type '(repeat string) |
851 | :version "20.8" | |
852 | :group 'SQL) | |
853 | ||
7492acc9 MM |
854 | (defcustom sql-mysql-login-params '(user password database server) |
855 | "List of login parameters needed to connect to MySql." | |
5474c40f | 856 | :type 'sql-login-params |
7492acc9 MM |
857 | :version "24.1" |
858 | :group 'SQL) | |
859 | ||
eb3f61dd | 860 | ;; Customization for Solid |
dab100d7 RS |
861 | |
862 | (defcustom sql-solid-program "solsql" | |
7492acc9 | 863 | "Command to start SOLID SQL Editor. |
dab100d7 | 864 | |
7492acc9 | 865 | Starts `sql-interactive-mode' after doing some setup." |
95e4b2ef RS |
866 | :type 'file |
867 | :group 'SQL) | |
868 | ||
7492acc9 MM |
869 | (defcustom sql-solid-login-params '(user password server) |
870 | "List of login parameters needed to connect to Solid." | |
5474c40f | 871 | :type 'sql-login-params |
7492acc9 MM |
872 | :version "24.1" |
873 | :group 'SQL) | |
874 | ||
c38762fd | 875 | ;; Customization for Sybase |
95e4b2ef RS |
876 | |
877 | (defcustom sql-sybase-program "isql" | |
c38762fd | 878 | "Command to start isql by Sybase. |
95e4b2ef | 879 | |
7492acc9 | 880 | Starts `sql-interactive-mode' after doing some setup." |
95e4b2ef RS |
881 | :type 'file |
882 | :group 'SQL) | |
883 | ||
9b5360aa | 884 | (defcustom sql-sybase-options nil |
7492acc9 | 885 | "List of additional options for `sql-sybase-program'. |
9b5360aa GM |
886 | Some versions of isql might require the -n option in order to work." |
887 | :type '(repeat string) | |
888 | :version "20.8" | |
889 | :group 'SQL) | |
890 | ||
7492acc9 MM |
891 | (defcustom sql-sybase-login-params '(server user password database) |
892 | "List of login parameters needed to connect to Sybase." | |
5474c40f | 893 | :type 'sql-login-params |
7492acc9 MM |
894 | :version "24.1" |
895 | :group 'SQL) | |
896 | ||
eb3f61dd | 897 | ;; Customization for Informix |
95e4b2ef RS |
898 | |
899 | (defcustom sql-informix-program "dbaccess" | |
7492acc9 | 900 | "Command to start dbaccess by Informix. |
95e4b2ef | 901 | |
7492acc9 | 902 | Starts `sql-interactive-mode' after doing some setup." |
95e4b2ef RS |
903 | :type 'file |
904 | :group 'SQL) | |
905 | ||
7492acc9 MM |
906 | (defcustom sql-informix-login-params '(database) |
907 | "List of login parameters needed to connect to Informix." | |
5474c40f | 908 | :type 'sql-login-params |
7492acc9 MM |
909 | :version "24.1" |
910 | :group 'SQL) | |
911 | ||
eb3f61dd | 912 | ;; Customization for Ingres |
95e4b2ef RS |
913 | |
914 | (defcustom sql-ingres-program "sql" | |
7492acc9 | 915 | "Command to start sql by Ingres. |
95e4b2ef | 916 | |
7492acc9 | 917 | Starts `sql-interactive-mode' after doing some setup." |
95e4b2ef RS |
918 | :type 'file |
919 | :group 'SQL) | |
920 | ||
7492acc9 MM |
921 | (defcustom sql-ingres-login-params '(database) |
922 | "List of login parameters needed to connect to Ingres." | |
5474c40f | 923 | :type 'sql-login-params |
7492acc9 MM |
924 | :version "24.1" |
925 | :group 'SQL) | |
926 | ||
eb3f61dd | 927 | ;; Customization for Microsoft |
95e4b2ef | 928 | |
78024f88 | 929 | (defcustom sql-ms-program "osql" |
7492acc9 | 930 | "Command to start osql by Microsoft. |
95e4b2ef | 931 | |
7492acc9 | 932 | Starts `sql-interactive-mode' after doing some setup." |
95e4b2ef RS |
933 | :type 'file |
934 | :group 'SQL) | |
935 | ||
f4df536d JB |
936 | (defcustom sql-ms-options '("-w" "300" "-n") |
937 | ;; -w is the linesize | |
7492acc9 | 938 | "List of additional options for `sql-ms-program'." |
f4df536d | 939 | :type '(repeat string) |
bf247b6e | 940 | :version "22.1" |
f4df536d JB |
941 | :group 'SQL) |
942 | ||
7492acc9 MM |
943 | (defcustom sql-ms-login-params '(user password server database) |
944 | "List of login parameters needed to connect to Microsoft." | |
5474c40f | 945 | :type 'sql-login-params |
7492acc9 MM |
946 | :version "24.1" |
947 | :group 'SQL) | |
948 | ||
eb3f61dd | 949 | ;; Customization for Postgres |
95e4b2ef RS |
950 | |
951 | (defcustom sql-postgres-program "psql" | |
801d1cb0 | 952 | "Command to start psql by Postgres. |
95e4b2ef | 953 | |
7492acc9 | 954 | Starts `sql-interactive-mode' after doing some setup." |
95e4b2ef RS |
955 | :type 'file |
956 | :group 'SQL) | |
957 | ||
524c8caf | 958 | (defcustom sql-postgres-options '("-P" "pager=off") |
7492acc9 | 959 | "List of additional options for `sql-postgres-program'. |
aa88e662 GM |
960 | The default setting includes the -P option which breaks older versions |
961 | of the psql client (such as version 6.5.3). The -P option is equivalent | |
962 | to the --pset option. If you want the psql to prompt you for a user | |
963 | name, add the string \"-u\" to the list of options. If you want to | |
964 | provide a user name on the command line (newer versions such as 7.1), | |
965 | add your name with a \"-U\" prefix (such as \"-Umark\") to the list." | |
311e7a89 GM |
966 | :type '(repeat string) |
967 | :version "20.8" | |
968 | :group 'SQL) | |
969 | ||
74790210 MM |
970 | (defcustom sql-postgres-login-params `((user :default ,(user-login-name)) |
971 | (database :default ,(user-login-name)) | |
972 | server) | |
7492acc9 | 973 | "List of login parameters needed to connect to Postgres." |
5474c40f | 974 | :type 'sql-login-params |
7492acc9 MM |
975 | :version "24.1" |
976 | :group 'SQL) | |
977 | ||
eb3f61dd GM |
978 | ;; Customization for Interbase |
979 | ||
980 | (defcustom sql-interbase-program "isql" | |
7492acc9 | 981 | "Command to start isql by Interbase. |
eb3f61dd | 982 | |
7492acc9 | 983 | Starts `sql-interactive-mode' after doing some setup." |
eb3f61dd GM |
984 | :type 'file |
985 | :group 'SQL) | |
986 | ||
987 | (defcustom sql-interbase-options nil | |
7492acc9 | 988 | "List of additional options for `sql-interbase-program'." |
eb3f61dd GM |
989 | :type '(repeat string) |
990 | :version "20.8" | |
991 | :group 'SQL) | |
992 | ||
7492acc9 MM |
993 | (defcustom sql-interbase-login-params '(user password database) |
994 | "List of login parameters needed to connect to Interbase." | |
5474c40f | 995 | :type 'sql-login-params |
7492acc9 MM |
996 | :version "24.1" |
997 | :group 'SQL) | |
998 | ||
624ef9b3 GM |
999 | ;; Customization for DB2 |
1000 | ||
1001 | (defcustom sql-db2-program "db2" | |
7492acc9 | 1002 | "Command to start db2 by IBM. |
624ef9b3 | 1003 | |
7492acc9 | 1004 | Starts `sql-interactive-mode' after doing some setup." |
624ef9b3 GM |
1005 | :type 'file |
1006 | :group 'SQL) | |
1007 | ||
1008 | (defcustom sql-db2-options nil | |
7492acc9 | 1009 | "List of additional options for `sql-db2-program'." |
624ef9b3 GM |
1010 | :type '(repeat string) |
1011 | :version "20.8" | |
1012 | :group 'SQL) | |
1013 | ||
7492acc9 MM |
1014 | (defcustom sql-db2-login-params nil |
1015 | "List of login parameters needed to connect to DB2." | |
5474c40f | 1016 | :type 'sql-login-params |
7492acc9 MM |
1017 | :version "24.1" |
1018 | :group 'SQL) | |
1019 | ||
f4df536d JB |
1020 | ;; Customization for Linter |
1021 | ||
1022 | (defcustom sql-linter-program "inl" | |
7492acc9 | 1023 | "Command to start inl by RELEX. |
f4df536d JB |
1024 | |
1025 | Starts `sql-interactive-mode' after doing some setup." | |
1026 | :type 'file | |
1027 | :group 'SQL) | |
1028 | ||
1029 | (defcustom sql-linter-options nil | |
7492acc9 | 1030 | "List of additional options for `sql-linter-program'." |
f4df536d JB |
1031 | :type '(repeat string) |
1032 | :version "21.3" | |
1033 | :group 'SQL) | |
1034 | ||
7492acc9 MM |
1035 | (defcustom sql-linter-login-params '(user password database server) |
1036 | "Login parameters to needed to connect to Linter." | |
5474c40f | 1037 | :type 'sql-login-params |
7492acc9 MM |
1038 | :version "24.1" |
1039 | :group 'SQL) | |
1040 | ||
95e4b2ef RS |
1041 | \f |
1042 | ||
1043 | ;;; Variables which do not need customization | |
1044 | ||
1045 | (defvar sql-user-history nil | |
1046 | "History of usernames used.") | |
1047 | ||
1048 | (defvar sql-database-history nil | |
1049 | "History of databases used.") | |
1050 | ||
1051 | (defvar sql-server-history nil | |
1052 | "History of servers used.") | |
1053 | ||
1054 | ;; Passwords are not kept in a history. | |
1055 | ||
74790210 MM |
1056 | (defvar sql-product-history nil |
1057 | "History of products used.") | |
1058 | ||
1059 | (defvar sql-connection-history nil | |
1060 | "History of connections used.") | |
1061 | ||
95e4b2ef | 1062 | (defvar sql-buffer nil |
dab100d7 RS |
1063 | "Current SQLi buffer. |
1064 | ||
063c6324 | 1065 | The global value of `sql-buffer' is the name of the latest SQLi buffer |
dab100d7 RS |
1066 | created. Any SQL buffer created will make a local copy of this value. |
1067 | See `sql-interactive-mode' for more on multiple sessions. If you want | |
1068 | to change the SQLi buffer a SQL mode sends its SQL strings to, change | |
c7055d66 | 1069 | the local value of `sql-buffer' using \\[sql-set-sqli-buffer].") |
95e4b2ef RS |
1070 | |
1071 | (defvar sql-prompt-regexp nil | |
1072 | "Prompt used to initialize `comint-prompt-regexp'. | |
1073 | ||
78024f88 | 1074 | You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.") |
95e4b2ef | 1075 | |
a081a529 RS |
1076 | (defvar sql-prompt-length 0 |
1077 | "Prompt used to set `left-margin' in `sql-interactive-mode'. | |
1078 | ||
78024f88 | 1079 | You can change `sql-prompt-length' on `sql-interactive-mode-hook'.") |
a081a529 | 1080 | |
3bd2cfef MM |
1081 | (defvar sql-prompt-cont-regexp nil |
1082 | "Prompt pattern of statement continuation prompts.") | |
1083 | ||
c7055d66 RS |
1084 | (defvar sql-alternate-buffer-name nil |
1085 | "Buffer-local string used to possibly rename the SQLi buffer. | |
1086 | ||
1087 | Used by `sql-rename-buffer'.") | |
1088 | ||
a386ac70 MM |
1089 | (defun sql-buffer-live-p (buffer &optional product) |
1090 | "Returns non-nil if the process associated with buffer is live. | |
1091 | ||
1092 | BUFFER can be a buffer object or a buffer name. The buffer must | |
1093 | be a live buffer, have an running process attached to it, be in | |
1094 | `sql-interactive-mode', and, if PRODUCT is specified, it's | |
1095 | `sql-product' must match." | |
1096 | ||
1097 | (when buffer | |
1098 | (setq buffer (get-buffer buffer)) | |
1099 | (and buffer | |
1100 | (buffer-live-p buffer) | |
1101 | (get-buffer-process buffer) | |
1102 | (comint-check-proc buffer) | |
1103 | (with-current-buffer buffer | |
74790210 | 1104 | (and (derived-mode-p 'sql-interactive-mode) |
a386ac70 MM |
1105 | (or (not product) |
1106 | (eq product sql-product))))))) | |
9250002f | 1107 | |
9ef3882f GM |
1108 | ;; Keymap for sql-interactive-mode. |
1109 | ||
f4df536d | 1110 | (defvar sql-interactive-mode-map |
9ef3882f | 1111 | (let ((map (make-sparse-keymap))) |
8d68e9b5 | 1112 | (if (fboundp 'set-keymap-parent) |
9ef3882f | 1113 | (set-keymap-parent map comint-mode-map); Emacs |
8d68e9b5 RS |
1114 | (if (fboundp 'set-keymap-parents) |
1115 | (set-keymap-parents map (list comint-mode-map)))); XEmacs | |
1116 | (if (fboundp 'set-keymap-name) | |
9ef3882f GM |
1117 | (set-keymap-name map 'sql-interactive-mode-map)); XEmacs |
1118 | (define-key map (kbd "C-j") 'sql-accumulate-and-indent) | |
1119 | (define-key map (kbd "C-c C-w") 'sql-copy-column) | |
1120 | (define-key map (kbd "O") 'sql-magic-go) | |
1121 | (define-key map (kbd "o") 'sql-magic-go) | |
1122 | (define-key map (kbd ";") 'sql-magic-semicolon) | |
74790210 MM |
1123 | (define-key map (kbd "C-c C-l a") 'sql-list-all) |
1124 | (define-key map (kbd "C-c C-l t") 'sql-list-table) | |
9ef3882f GM |
1125 | map) |
1126 | "Mode map used for `sql-interactive-mode'. | |
1127 | Based on `comint-mode-map'.") | |
95e4b2ef RS |
1128 | |
1129 | ;; Keymap for sql-mode. | |
1130 | ||
1131 | (defvar sql-mode-map | |
1132 | (let ((map (make-sparse-keymap))) | |
9ef3882f GM |
1133 | (define-key map (kbd "C-c C-c") 'sql-send-paragraph) |
1134 | (define-key map (kbd "C-c C-r") 'sql-send-region) | |
9fd8cb36 | 1135 | (define-key map (kbd "C-c C-s") 'sql-send-string) |
9ef3882f | 1136 | (define-key map (kbd "C-c C-b") 'sql-send-buffer) |
7492acc9 | 1137 | (define-key map (kbd "C-c C-i") 'sql-product-interactive) |
74790210 MM |
1138 | (define-key map (kbd "C-c C-l a") 'sql-list-all) |
1139 | (define-key map (kbd "C-c C-l t") 'sql-list-table) | |
95e4b2ef RS |
1140 | map) |
1141 | "Mode map used for `sql-mode'.") | |
1142 | ||
1143 | ;; easy menu for sql-mode. | |
1144 | ||
801d1cb0 AS |
1145 | (easy-menu-define |
1146 | sql-mode-menu sql-mode-map | |
95e4b2ef | 1147 | "Menu for `sql-mode'." |
55659495 | 1148 | `("SQL" |
9250002f | 1149 | ["Send Paragraph" sql-send-paragraph (sql-buffer-live-p sql-buffer)] |
7492acc9 | 1150 | ["Send Region" sql-send-region (and mark-active |
9250002f MM |
1151 | (sql-buffer-live-p sql-buffer))] |
1152 | ["Send Buffer" sql-send-buffer (sql-buffer-live-p sql-buffer)] | |
1153 | ["Send String" sql-send-string (sql-buffer-live-p sql-buffer)] | |
d26b0ea9 | 1154 | "--" |
74790210 MM |
1155 | ["List all objects" sql-list-all (sql-buffer-live-p sql-buffer)] |
1156 | ["List table details" sql-list-table (sql-buffer-live-p sql-buffer)] | |
1157 | "--" | |
d26b0ea9 MM |
1158 | ["Start SQLi session" sql-product-interactive |
1159 | :visible (not sql-connection-alist) | |
1160 | :enable (sql-get-product-feature sql-product :sqli-comint-func)] | |
1161 | ("Start..." | |
1162 | :visible sql-connection-alist | |
1163 | :filter sql-connection-menu-filter | |
1164 | "--" | |
1165 | ["New SQLi Session" sql-product-interactive (sql-get-product-feature sql-product :sqli-comint-func)]) | |
1166 | ["--" | |
1167 | :visible sql-connection-alist] | |
dab100d7 | 1168 | ["Show SQLi buffer" sql-show-sqli-buffer t] |
c7055d66 | 1169 | ["Set SQLi buffer" sql-set-sqli-buffer t] |
801d1cb0 | 1170 | ["Pop to SQLi buffer after send" |
95e4b2ef RS |
1171 | sql-toggle-pop-to-buffer-after-send-region |
1172 | :style toggle | |
624ef9b3 | 1173 | :selected sql-pop-to-buffer-after-send-region] |
78024f88 AS |
1174 | ["--" nil nil] |
1175 | ("Product" | |
55659495 SM |
1176 | ,@(mapcar (lambda (prod-info) |
1177 | (let* ((prod (pop prod-info)) | |
1178 | (name (or (plist-get prod-info :name) | |
1179 | (capitalize (symbol-name prod)))) | |
1180 | (cmd (intern (format "sql-highlight-%s-keywords" prod)))) | |
1181 | (fset cmd `(lambda () ,(format "Highlight %s SQL keywords." name) | |
1182 | (interactive) | |
1183 | (sql-set-product ',prod))) | |
1184 | (vector name cmd | |
1185 | :style 'radio | |
1186 | :selected `(eq sql-product ',prod)))) | |
1187 | sql-product-alist)))) | |
95e4b2ef | 1188 | |
c7055d66 RS |
1189 | ;; easy menu for sql-interactive-mode. |
1190 | ||
801d1cb0 | 1191 | (easy-menu-define |
c7055d66 RS |
1192 | sql-interactive-mode-menu sql-interactive-mode-map |
1193 | "Menu for `sql-interactive-mode'." | |
1194 | '("SQL" | |
d26b0ea9 | 1195 | ["Rename Buffer" sql-rename-buffer t] |
74790210 MM |
1196 | ["Save Connection" sql-save-connection (not sql-connection)] |
1197 | "--" | |
1198 | ["List all objects" sql-list-all t] | |
1199 | ["List table details" sql-list-table t])) | |
c7055d66 | 1200 | |
95e4b2ef RS |
1201 | ;; Abbreviations -- if you want more of them, define them in your |
1202 | ;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too. | |
1203 | ||
1204 | (defvar sql-mode-abbrev-table nil | |
1205 | "Abbrev table used in `sql-mode' and `sql-interactive-mode'.") | |
9fd8cb36 | 1206 | (unless sql-mode-abbrev-table |
e5a4bf48 GM |
1207 | (define-abbrev-table 'sql-mode-abbrev-table nil)) |
1208 | ||
f77183c0 | 1209 | (mapc |
01295a22 | 1210 | ;; In Emacs 22+, provide SYSTEM-FLAG to define-abbrev. |
e5a4bf48 GM |
1211 | '(lambda (abbrev) |
1212 | (let ((name (car abbrev)) | |
1213 | (expansion (cdr abbrev))) | |
1214 | (condition-case nil | |
1215 | (define-abbrev sql-mode-abbrev-table name expansion nil 0 t) | |
1216 | (error | |
1217 | (define-abbrev sql-mode-abbrev-table name expansion))))) | |
01295a22 RS |
1218 | '(("ins" . "insert") |
1219 | ("upd" . "update") | |
1220 | ("del" . "delete") | |
1221 | ("sel" . "select") | |
1222 | ("proc" . "procedure") | |
1223 | ("func" . "function") | |
1224 | ("cr" . "create"))) | |
95e4b2ef RS |
1225 | |
1226 | ;; Syntax Table | |
1227 | ||
801d1cb0 | 1228 | (defvar sql-mode-syntax-table |
95e4b2ef RS |
1229 | (let ((table (make-syntax-table))) |
1230 | ;; C-style comments /**/ (see elisp manual "Syntax Flags")) | |
1231 | (modify-syntax-entry ?/ ". 14" table) | |
1232 | (modify-syntax-entry ?* ". 23" table) | |
01295a22 | 1233 | ;; double-dash starts comments |
9a9069c9 | 1234 | (modify-syntax-entry ?- ". 12b" table) |
01295a22 | 1235 | ;; newline and formfeed end comments |
95e4b2ef RS |
1236 | (modify-syntax-entry ?\n "> b" table) |
1237 | (modify-syntax-entry ?\f "> b" table) | |
01295a22 | 1238 | ;; single quotes (') delimit strings |
a081a529 | 1239 | (modify-syntax-entry ?' "\"" table) |
01295a22 RS |
1240 | ;; double quotes (") don't delimit strings |
1241 | (modify-syntax-entry ?\" "." table) | |
4da8ff79 RS |
1242 | ;; backslash is no escape character |
1243 | (modify-syntax-entry ?\\ "." table) | |
95e4b2ef RS |
1244 | table) |
1245 | "Syntax table used in `sql-mode' and `sql-interactive-mode'.") | |
1246 | ||
1247 | ;; Font lock support | |
1248 | ||
78024f88 | 1249 | (defvar sql-mode-font-lock-object-name |
01295a22 RS |
1250 | (eval-when-compile |
1251 | (list (concat "^\\s-*\\(?:create\\|drop\\|alter\\)\\s-+" ;; lead off with CREATE, DROP or ALTER | |
1252 | "\\(?:\\w+\\s-+\\)*" ;; optional intervening keywords | |
1253 | "\\(?:table\\|view\\|\\(?:package\\|type\\)\\(?:\\s-+body\\)?\\|proc\\(?:edure\\)?" | |
1254 | "\\|function\\|trigger\\|sequence\\|rule\\|default\\)\\s-+" | |
1255 | "\\(\\w+\\)") | |
1256 | 1 'font-lock-function-name-face)) | |
9fd8cb36 SM |
1257 | |
1258 | "Pattern to match the names of top-level objects. | |
1259 | ||
1260 | The pattern matches the name in a CREATE, DROP or ALTER | |
1261 | statement. The format of variable should be a valid | |
1262 | `font-lock-keywords' entry.") | |
1263 | ||
7492acc9 MM |
1264 | ;; While there are international and American standards for SQL, they |
1265 | ;; are not followed closely, and most vendors offer significant | |
1266 | ;; capabilities beyond those defined in the standard specifications. | |
1267 | ||
1268 | ;; SQL mode provides support for hilighting based on the product. In | |
1269 | ;; addition to hilighting the product keywords, any ANSI keywords not | |
1270 | ;; used by the product are also hilighted. This will help identify | |
1271 | ;; keywords that could be restricted in future versions of the product | |
1272 | ;; or might be a problem if ported to another product. | |
1273 | ||
1274 | ;; To reduce the complexity and size of the regular expressions | |
1275 | ;; generated to match keywords, ANSI keywords are filtered out of | |
1276 | ;; product keywords if they are equivalent. To do this, we define a | |
1277 | ;; function `sql-font-lock-keywords-builder' that removes any keywords | |
1278 | ;; that are matched by the ANSI patterns and results in the same face | |
1279 | ;; being applied. For this to work properly, we must play some games | |
1280 | ;; with the execution and compile time behavior. This code is a | |
1281 | ;; little tricky but works properly. | |
1282 | ||
1283 | ;; When defining the keywords for individual products you should | |
1284 | ;; include all of the keywords that you want matched. The filtering | |
1285 | ;; against the ANSI keywords will be automatic if you use the | |
1286 | ;; `sql-font-lock-keywords-builder' function and follow the | |
1287 | ;; implementation pattern used for the other products in this file. | |
78024f88 | 1288 | |
7492acc9 MM |
1289 | (eval-when-compile |
1290 | (defvar sql-mode-ansi-font-lock-keywords) | |
1291 | (setq sql-mode-ansi-font-lock-keywords nil)) | |
1292 | ||
1293 | (eval-and-compile | |
1294 | (defun sql-font-lock-keywords-builder (face boundaries &rest keywords) | |
1295 | "Generation of regexp matching any one of KEYWORDS." | |
1296 | ||
1297 | (let ((bdy (or boundaries '("\\b" . "\\b"))) | |
1298 | kwd) | |
1299 | ||
1300 | ;; Remove keywords that are defined in ANSI | |
1301 | (setq kwd keywords) | |
1302 | (dolist (k keywords) | |
1303 | (catch 'next | |
1304 | (dolist (a sql-mode-ansi-font-lock-keywords) | |
1305 | (when (and (eq face (cdr a)) | |
1306 | (eq (string-match (car a) k 0) 0) | |
1307 | (eq (match-end 0) (length k))) | |
1308 | (setq kwd (delq k kwd)) | |
1309 | (throw 'next nil))))) | |
1310 | ||
1311 | ;; Create a properly formed font-lock-keywords item | |
1312 | (cons (concat (car bdy) | |
1313 | (regexp-opt kwd t) | |
1314 | (cdr bdy)) | |
1315 | face)))) | |
9fd8cb36 | 1316 | |
7492acc9 MM |
1317 | (eval-when-compile |
1318 | (setq sql-mode-ansi-font-lock-keywords | |
1319 | (list | |
1320 | ;; ANSI Non Reserved keywords | |
1321 | (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
9fd8cb36 SM |
1322 | "ada" "asensitive" "assignment" "asymmetric" "atomic" "between" |
1323 | "bitvar" "called" "catalog_name" "chain" "character_set_catalog" | |
1324 | "character_set_name" "character_set_schema" "checked" "class_origin" | |
1325 | "cobol" "collation_catalog" "collation_name" "collation_schema" | |
1326 | "column_name" "command_function" "command_function_code" "committed" | |
1327 | "condition_number" "connection_name" "constraint_catalog" | |
1328 | "constraint_name" "constraint_schema" "contains" "cursor_name" | |
1329 | "datetime_interval_code" "datetime_interval_precision" "defined" | |
1330 | "definer" "dispatch" "dynamic_function" "dynamic_function_code" | |
1331 | "existing" "exists" "final" "fortran" "generated" "granted" | |
1332 | "hierarchy" "hold" "implementation" "infix" "insensitive" "instance" | |
1333 | "instantiable" "invoker" "key_member" "key_type" "length" "m" | |
1334 | "message_length" "message_octet_length" "message_text" "method" "more" | |
1335 | "mumps" "name" "nullable" "number" "options" "overlaps" "overriding" | |
1336 | "parameter_mode" "parameter_name" "parameter_ordinal_position" | |
1337 | "parameter_specific_catalog" "parameter_specific_name" | |
1338 | "parameter_specific_schema" "pascal" "pli" "position" "repeatable" | |
1339 | "returned_length" "returned_octet_length" "returned_sqlstate" | |
1340 | "routine_catalog" "routine_name" "routine_schema" "row_count" "scale" | |
1341 | "schema_name" "security" "self" "sensitive" "serializable" | |
1342 | "server_name" "similar" "simple" "source" "specific_name" "style" | |
1343 | "subclass_origin" "sublist" "symmetric" "system" "table_name" | |
1344 | "transaction_active" "transactions_committed" | |
1345 | "transactions_rolled_back" "transform" "transforms" "trigger_catalog" | |
1346 | "trigger_name" "trigger_schema" "type" "uncommitted" "unnamed" | |
1347 | "user_defined_type_catalog" "user_defined_type_name" | |
1348 | "user_defined_type_schema" | |
7492acc9 MM |
1349 | ) |
1350 | ;; ANSI Reserved keywords | |
1351 | (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
9fd8cb36 SM |
1352 | "absolute" "action" "add" "admin" "after" "aggregate" "alias" "all" |
1353 | "allocate" "alter" "and" "any" "are" "as" "asc" "assertion" "at" | |
1354 | "authorization" "before" "begin" "both" "breadth" "by" "call" | |
1355 | "cascade" "cascaded" "case" "catalog" "check" "class" "close" | |
1356 | "collate" "collation" "column" "commit" "completion" "connect" | |
1357 | "connection" "constraint" "constraints" "constructor" "continue" | |
1358 | "corresponding" "create" "cross" "cube" "current" "cursor" "cycle" | |
1359 | "data" "day" "deallocate" "declare" "default" "deferrable" "deferred" | |
1360 | "delete" "depth" "deref" "desc" "describe" "descriptor" "destroy" | |
1361 | "destructor" "deterministic" "diagnostics" "dictionary" "disconnect" | |
1362 | "distinct" "domain" "drop" "dynamic" "each" "else" "end" "equals" | |
1363 | "escape" "every" "except" "exception" "exec" "execute" "external" | |
1364 | "false" "fetch" "first" "for" "foreign" "found" "free" "from" "full" | |
1365 | "function" "general" "get" "global" "go" "goto" "grant" "group" | |
1366 | "grouping" "having" "host" "hour" "identity" "ignore" "immediate" "in" | |
1367 | "indicator" "initialize" "initially" "inner" "inout" "input" "insert" | |
1368 | "intersect" "into" "is" "isolation" "iterate" "join" "key" "language" | |
1369 | "last" "lateral" "leading" "left" "less" "level" "like" "limit" | |
1370 | "local" "locator" "map" "match" "minute" "modifies" "modify" "module" | |
1371 | "month" "names" "natural" "new" "next" "no" "none" "not" "null" "of" | |
1372 | "off" "old" "on" "only" "open" "operation" "option" "or" "order" | |
1373 | "ordinality" "out" "outer" "output" "pad" "parameter" "parameters" | |
1374 | "partial" "path" "postfix" "prefix" "preorder" "prepare" "preserve" | |
1375 | "primary" "prior" "privileges" "procedure" "public" "read" "reads" | |
1376 | "recursive" "references" "referencing" "relative" "restrict" "result" | |
1377 | "return" "returns" "revoke" "right" "role" "rollback" "rollup" | |
1378 | "routine" "rows" "savepoint" "schema" "scroll" "search" "second" | |
1379 | "section" "select" "sequence" "session" "set" "sets" "size" "some" | |
1380 | "space" "specific" "specifictype" "sql" "sqlexception" "sqlstate" | |
1381 | "sqlwarning" "start" "state" "statement" "static" "structure" "table" | |
1382 | "temporary" "terminate" "than" "then" "timezone_hour" | |
1383 | "timezone_minute" "to" "trailing" "transaction" "translation" | |
1384 | "trigger" "true" "under" "union" "unique" "unknown" "unnest" "update" | |
1385 | "usage" "using" "value" "values" "variable" "view" "when" "whenever" | |
1386 | "where" "with" "without" "work" "write" "year" | |
7492acc9 | 1387 | ) |
9fd8cb36 | 1388 | |
7492acc9 MM |
1389 | ;; ANSI Functions |
1390 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
1391 | "abs" "avg" "bit_length" "cardinality" "cast" "char_length" | |
1392 | "character_length" "coalesce" "convert" "count" "current_date" | |
1393 | "current_path" "current_role" "current_time" "current_timestamp" | |
1394 | "current_user" "extract" "localtime" "localtimestamp" "lower" "max" | |
1395 | "min" "mod" "nullif" "octet_length" "overlay" "placing" "session_user" | |
1396 | "substring" "sum" "system_user" "translate" "treat" "trim" "upper" | |
1397 | "user" | |
1398 | ) | |
1399 | ;; ANSI Data Types | |
1400 | (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
9fd8cb36 SM |
1401 | "array" "binary" "bit" "blob" "boolean" "char" "character" "clob" |
1402 | "date" "dec" "decimal" "double" "float" "int" "integer" "interval" | |
1403 | "large" "national" "nchar" "nclob" "numeric" "object" "precision" | |
1404 | "real" "ref" "row" "scope" "smallint" "time" "timestamp" "varchar" | |
1405 | "varying" "zone" | |
7492acc9 | 1406 | )))) |
95e4b2ef | 1407 | |
7492acc9 MM |
1408 | (defvar sql-mode-ansi-font-lock-keywords |
1409 | (eval-when-compile sql-mode-ansi-font-lock-keywords) | |
78024f88 | 1410 | "ANSI SQL keywords used by font-lock. |
95e4b2ef RS |
1411 | |
1412 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1413 | regular expressions are created during compilation by calling the | |
1414 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 JB |
1415 | you define your own `sql-mode-ansi-font-lock-keywords'. You may want |
1416 | to add functions and PL/SQL keywords.") | |
78024f88 AS |
1417 | |
1418 | (defvar sql-mode-oracle-font-lock-keywords | |
7492acc9 MM |
1419 | (eval-when-compile |
1420 | (list | |
1421 | ;; Oracle SQL*Plus Commands | |
1422 | (cons | |
1423 | (concat | |
9250002f | 1424 | "^\\s-*\\(?:\\(?:" (regexp-opt '( |
7492acc9 MM |
1425 | "@" "@@" "accept" "append" "archive" "attribute" "break" |
1426 | "btitle" "change" "clear" "column" "connect" "copy" "define" | |
1427 | "del" "describe" "disconnect" "edit" "execute" "exit" "get" "help" | |
1428 | "host" "input" "list" "password" "pause" "print" "prompt" "recover" | |
1429 | "remark" "repfooter" "repheader" "run" "save" "show" "shutdown" | |
1430 | "spool" "start" "startup" "store" "timing" "ttitle" "undefine" | |
1431 | "variable" "whenever" | |
1432 | ) t) | |
1433 | ||
1434 | "\\)\\|" | |
1435 | "\\(?:compute\\s-+\\(?:avg\\|cou\\|min\\|max\\|num\\|sum\\|std\\|var\\)\\)\\|" | |
1436 | "\\(?:set\\s-+\\(" | |
1437 | ||
1438 | (regexp-opt | |
1439 | '("appi" "appinfo" "array" "arraysize" "auto" "autocommit" | |
1440 | "autop" "autoprint" "autorecovery" "autot" "autotrace" "blo" | |
1441 | "blockterminator" "buffer" "closecursor" "cmds" "cmdsep" | |
1442 | "colsep" "com" "compatibility" "con" "concat" "constraint" | |
1443 | "constraints" "copyc" "copycommit" "copytypecheck" "database" | |
1444 | "def" "define" "document" "echo" "editf" "editfile" "emb" | |
1445 | "embedded" "esc" "escape" "feed" "feedback" "flagger" "flu" | |
1446 | "flush" "hea" "heading" "heads" "headsep" "instance" "lin" | |
1447 | "linesize" "lobof" "loboffset" "logsource" "long" "longc" | |
1448 | "longchunksize" "maxdata" "newp" "newpage" "null" "num" | |
1449 | "numf" "numformat" "numwidth" "pages" "pagesize" "pau" | |
1450 | "pause" "recsep" "recsepchar" "role" "scan" "serveroutput" | |
1451 | "shift" "shiftinout" "show" "showmode" "space" "sqlbl" | |
1452 | "sqlblanklines" "sqlc" "sqlcase" "sqlco" "sqlcontinue" "sqln" | |
1453 | "sqlnumber" "sqlp" "sqlpluscompat" "sqlpluscompatibility" | |
1454 | "sqlpre" "sqlprefix" "sqlprompt" "sqlt" "sqlterminator" | |
1455 | "statement_id" "suf" "suffix" "tab" "term" "termout" "ti" | |
1456 | "time" "timi" "timing" "transaction" "trim" "trimout" "trims" | |
1457 | "trimspool" "truncate" "und" "underline" "ver" "verify" "wra" | |
1458 | "wrap")) "\\)\\)" | |
1459 | ||
1460 | "\\)\\b.*" | |
1461 | ) | |
1462 | 'font-lock-doc-face) | |
9250002f | 1463 | '("^\\s-*rem\\(?:ark\\)?\\>.*" . font-lock-comment-face) |
7492acc9 MM |
1464 | |
1465 | ;; Oracle Functions | |
1466 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
9fd8cb36 SM |
1467 | "abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2" |
1468 | "avg" "bfilename" "bin_to_num" "bitand" "cast" "ceil" "chartorowid" | |
1469 | "chr" "coalesce" "compose" "concat" "convert" "corr" "cos" "cosh" | |
1470 | "count" "covar_pop" "covar_samp" "cume_dist" "current_date" | |
1471 | "current_timestamp" "current_user" "dbtimezone" "decode" "decompose" | |
1472 | "dense_rank" "depth" "deref" "dump" "empty_clob" "existsnode" "exp" | |
1473 | "extract" "extractvalue" "first" "first_value" "floor" "following" | |
1474 | "from_tz" "greatest" "group_id" "grouping_id" "hextoraw" "initcap" | |
1475 | "instr" "lag" "last" "last_day" "last_value" "lead" "least" "length" | |
1476 | "ln" "localtimestamp" "lower" "lpad" "ltrim" "make_ref" "max" "min" | |
1477 | "mod" "months_between" "new_time" "next_day" "nls_charset_decl_len" | |
1478 | "nls_charset_id" "nls_charset_name" "nls_initcap" "nls_lower" | |
1479 | "nls_upper" "nlssort" "ntile" "nullif" "numtodsinterval" | |
1480 | "numtoyminterval" "nvl" "nvl2" "over" "path" "percent_rank" | |
1481 | "percentile_cont" "percentile_disc" "power" "preceding" "rank" | |
1482 | "ratio_to_report" "rawtohex" "rawtonhex" "reftohex" "regr_" | |
1483 | "regr_avgx" "regr_avgy" "regr_count" "regr_intercept" "regr_r2" | |
1484 | "regr_slope" "regr_sxx" "regr_sxy" "regr_syy" "replace" "round" | |
1485 | "row_number" "rowidtochar" "rowidtonchar" "rpad" "rtrim" | |
1486 | "sessiontimezone" "sign" "sin" "sinh" "soundex" "sqrt" "stddev" | |
1487 | "stddev_pop" "stddev_samp" "substr" "sum" "sys_connect_by_path" | |
1488 | "sys_context" "sys_dburigen" "sys_extract_utc" "sys_guid" "sys_typeid" | |
1489 | "sys_xmlagg" "sys_xmlgen" "sysdate" "systimestamp" "tan" "tanh" | |
1490 | "to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte" | |
1491 | "to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp" | |
1492 | "to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc" | |
1493 | "tz_offset" "uid" "unbounded" "unistr" "updatexml" "upper" "user" | |
1494 | "userenv" "var_pop" "var_samp" "variance" "vsize" "width_bucket" "xml" | |
1495 | "xmlagg" "xmlattribute" "xmlcolattval" "xmlconcat" "xmlelement" | |
1496 | "xmlforest" "xmlsequence" "xmltransform" | |
7492acc9 MM |
1497 | ) |
1498 | ;; Oracle Keywords | |
1499 | (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
9fd8cb36 SM |
1500 | "abort" "access" "accessed" "account" "activate" "add" "admin" |
1501 | "advise" "after" "agent" "aggregate" "all" "allocate" "allow" "alter" | |
1502 | "always" "analyze" "ancillary" "and" "any" "apply" "archive" | |
1503 | "archivelog" "array" "as" "asc" "associate" "at" "attribute" | |
1504 | "attributes" "audit" "authenticated" "authid" "authorization" "auto" | |
1505 | "autoallocate" "automatic" "availability" "backup" "before" "begin" | |
1506 | "behalf" "between" "binding" "bitmap" "block" "blocksize" "body" | |
1507 | "both" "buffer_pool" "build" "by" "cache" "call" "cancel" | |
1508 | "cascade" "case" "category" "certificate" "chained" "change" "check" | |
1509 | "checkpoint" "child" "chunk" "class" "clear" "clone" "close" "cluster" | |
1510 | "column" "column_value" "columns" "comment" "commit" "committed" | |
1511 | "compatibility" "compile" "complete" "composite_limit" "compress" | |
1512 | "compute" "connect" "connect_time" "consider" "consistent" | |
1513 | "constraint" "constraints" "constructor" "contents" "context" | |
1514 | "continue" "controlfile" "corruption" "cost" "cpu_per_call" | |
1515 | "cpu_per_session" "create" "cross" "cube" "current" "currval" "cycle" | |
1516 | "dangling" "data" "database" "datafile" "datafiles" "day" "ddl" | |
1517 | "deallocate" "debug" "default" "deferrable" "deferred" "definer" | |
1518 | "delay" "delete" "demand" "desc" "determines" "deterministic" | |
1519 | "dictionary" "dimension" "directory" "disable" "disassociate" | |
1520 | "disconnect" "distinct" "distinguished" "distributed" "dml" "drop" | |
1521 | "each" "element" "else" "enable" "end" "equals_path" "escape" | |
1522 | "estimate" "except" "exceptions" "exchange" "excluding" "exists" | |
1523 | "expire" "explain" "extent" "external" "externally" | |
1524 | "failed_login_attempts" "fast" "file" "final" "finish" "flush" "for" | |
1525 | "force" "foreign" "freelist" "freelists" "freepools" "fresh" "from" | |
1526 | "full" "function" "functions" "generated" "global" "global_name" | |
1527 | "globally" "grant" "group" "grouping" "groups" "guard" "hash" | |
1528 | "hashkeys" "having" "heap" "hierarchy" "id" "identified" "identifier" | |
1529 | "idle_time" "immediate" "in" "including" "increment" "index" "indexed" | |
1530 | "indexes" "indextype" "indextypes" "indicator" "initial" "initialized" | |
1531 | "initially" "initrans" "inner" "insert" "instance" "instantiable" | |
1532 | "instead" "intersect" "into" "invalidate" "is" "isolation" "java" | |
1533 | "join" "keep" "key" "kill" "language" "left" "less" "level" | |
1534 | "levels" "library" "like" "like2" "like4" "likec" "limit" "link" | |
1535 | "list" "lob" "local" "location" "locator" "lock" "log" "logfile" | |
1536 | "logging" "logical" "logical_reads_per_call" | |
1537 | "logical_reads_per_session" "managed" "management" "manual" "map" | |
1538 | "mapping" "master" "matched" "materialized" "maxdatafiles" | |
1539 | "maxextents" "maximize" "maxinstances" "maxlogfiles" "maxloghistory" | |
1540 | "maxlogmembers" "maxsize" "maxtrans" "maxvalue" "member" "memory" | |
1541 | "merge" "migrate" "minextents" "minimize" "minimum" "minus" "minvalue" | |
1542 | "mode" "modify" "monitoring" "month" "mount" "move" "movement" "name" | |
1543 | "named" "natural" "nested" "never" "new" "next" "nextval" "no" | |
1544 | "noarchivelog" "noaudit" "nocache" "nocompress" "nocopy" "nocycle" | |
1545 | "nodelay" "noforce" "nologging" "nomapping" "nomaxvalue" "nominimize" | |
1546 | "nominvalue" "nomonitoring" "none" "noorder" "noparallel" "norely" | |
1547 | "noresetlogs" "noreverse" "normal" "norowdependencies" "nosort" | |
1548 | "noswitch" "not" "nothing" "notimeout" "novalidate" "nowait" "null" | |
1549 | "nulls" "object" "of" "off" "offline" "oidindex" "old" "on" "online" | |
1550 | "only" "open" "operator" "optimal" "option" "or" "order" | |
1551 | "organization" "out" "outer" "outline" "overflow" "overriding" | |
1552 | "package" "packages" "parallel" "parallel_enable" "parameters" | |
1553 | "parent" "partition" "partitions" "password" "password_grace_time" | |
1554 | "password_life_time" "password_lock_time" "password_reuse_max" | |
1555 | "password_reuse_time" "password_verify_function" "pctfree" | |
1556 | "pctincrease" "pctthreshold" "pctused" "pctversion" "percent" | |
1557 | "performance" "permanent" "pfile" "physical" "pipelined" "plan" | |
1558 | "post_transaction" "pragma" "prebuilt" "preserve" "primary" "private" | |
1559 | "private_sga" "privileges" "procedure" "profile" "protection" "public" | |
1560 | "purge" "query" "quiesce" "quota" "range" "read" "reads" "rebuild" | |
1561 | "records_per_block" "recover" "recovery" "recycle" "reduced" "ref" | |
1562 | "references" "referencing" "refresh" "register" "reject" "relational" | |
1563 | "rely" "rename" "reset" "resetlogs" "resize" "resolve" "resolver" | |
1564 | "resource" "restrict" "restrict_references" "restricted" "result" | |
1565 | "resumable" "resume" "retention" "return" "returning" "reuse" | |
1566 | "reverse" "revoke" "rewrite" "right" "rnds" "rnps" "role" "roles" | |
1567 | "rollback" "rollup" "row" "rowdependencies" "rownum" "rows" "sample" | |
1568 | "savepoint" "scan" "schema" "scn" "scope" "segment" "select" | |
1569 | "selectivity" "self" "sequence" "serializable" "session" | |
1570 | "sessions_per_user" "set" "sets" "settings" "shared" "shared_pool" | |
1571 | "shrink" "shutdown" "siblings" "sid" "single" "size" "skip" "some" | |
1572 | "sort" "source" "space" "specification" "spfile" "split" "standby" | |
1573 | "start" "statement_id" "static" "statistics" "stop" "storage" "store" | |
1574 | "structure" "subpartition" "subpartitions" "substitutable" | |
1575 | "successful" "supplemental" "suspend" "switch" "switchover" "synonym" | |
1576 | "sys" "system" "table" "tables" "tablespace" "tempfile" "template" | |
1577 | "temporary" "test" "than" "then" "thread" "through" "time_zone" | |
1578 | "timeout" "to" "trace" "transaction" "trigger" "triggers" "truncate" | |
1579 | "trust" "type" "types" "unarchived" "under" "under_path" "undo" | |
1580 | "uniform" "union" "unique" "unlimited" "unlock" "unquiesce" | |
1581 | "unrecoverable" "until" "unusable" "unused" "update" "upgrade" "usage" | |
1582 | "use" "using" "validate" "validation" "value" "values" "variable" | |
1583 | "varray" "version" "view" "wait" "when" "whenever" "where" "with" | |
1584 | "without" "wnds" "wnps" "work" "write" "xmldata" "xmlschema" "xmltype" | |
7492acc9 MM |
1585 | ) |
1586 | ;; Oracle Data Types | |
1587 | (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
9fd8cb36 SM |
1588 | "bfile" "blob" "byte" "char" "character" "clob" "date" "dec" "decimal" |
1589 | "double" "float" "int" "integer" "interval" "long" "national" "nchar" | |
1590 | "nclob" "number" "numeric" "nvarchar2" "precision" "raw" "real" | |
1591 | "rowid" "second" "smallint" "time" "timestamp" "urowid" "varchar" | |
1592 | "varchar2" "varying" "year" "zone" | |
7492acc9 | 1593 | ) |
9fd8cb36 | 1594 | |
7492acc9 MM |
1595 | ;; Oracle PL/SQL Attributes |
1596 | (sql-font-lock-keywords-builder 'font-lock-builtin-face '("" . "\\b") | |
9fd8cb36 | 1597 | "%bulk_rowcount" "%found" "%isopen" "%notfound" "%rowcount" "%rowtype" |
7492acc9 MM |
1598 | "%type" |
1599 | ) | |
1600 | ||
1601 | ;; Oracle PL/SQL Functions | |
1602 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
1603 | "extend" "prior" | |
1604 | ) | |
9fd8cb36 | 1605 | |
7492acc9 MM |
1606 | ;; Oracle PL/SQL Keywords |
1607 | (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
9fd8cb36 SM |
1608 | "autonomous_transaction" "bulk" "char_base" "collect" "constant" |
1609 | "cursor" "declare" "do" "elsif" "exception_init" "execute" "exit" | |
1610 | "extends" "false" "fetch" "forall" "goto" "hour" "if" "interface" | |
1611 | "loop" "minute" "number_base" "ocirowid" "opaque" "others" "rowtype" | |
1612 | "separate" "serially_reusable" "sql" "sqlcode" "sqlerrm" "subtype" | |
1613 | "the" "timezone_abbr" "timezone_hour" "timezone_minute" | |
1614 | "timezone_region" "true" "varrying" "while" | |
7492acc9 | 1615 | ) |
9fd8cb36 | 1616 | |
7492acc9 MM |
1617 | ;; Oracle PL/SQL Data Types |
1618 | (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
9fd8cb36 SM |
1619 | "binary_integer" "boolean" "naturaln" "pls_integer" "positive" |
1620 | "positiven" "record" "signtype" "string" | |
7492acc9 | 1621 | ) |
9fd8cb36 | 1622 | |
7492acc9 MM |
1623 | ;; Oracle PL/SQL Exceptions |
1624 | (sql-font-lock-keywords-builder 'font-lock-warning-face nil | |
78024f88 AS |
1625 | "access_into_null" "case_not_found" "collection_is_null" |
1626 | "cursor_already_open" "dup_val_on_index" "invalid_cursor" | |
77d352a6 | 1627 | "invalid_number" "login_denied" "no_data_found" "not_logged_on" |
78024f88 AS |
1628 | "program_error" "rowtype_mismatch" "self_is_null" "storage_error" |
1629 | "subscript_beyond_count" "subscript_outside_limit" "sys_invalid_rowid" | |
1630 | "timeout_on_resource" "too_many_rows" "value_error" "zero_divide" | |
1631 | "exception" "notfound" | |
7492acc9 | 1632 | ))) |
95e4b2ef | 1633 | |
78024f88 | 1634 | "Oracle SQL keywords used by font-lock. |
95e4b2ef RS |
1635 | |
1636 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1637 | regular expressions are created during compilation by calling the | |
1638 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 | 1639 | you define your own `sql-mode-oracle-font-lock-keywords'. You may want |
78024f88 | 1640 | to add functions and PL/SQL keywords.") |
95e4b2ef | 1641 | |
78024f88 | 1642 | (defvar sql-mode-postgres-font-lock-keywords |
7492acc9 MM |
1643 | (eval-when-compile |
1644 | (list | |
9250002f MM |
1645 | ;; Postgres psql commands |
1646 | '("^\\s-*\\\\.*$" . font-lock-doc-face) | |
1647 | ||
1648 | ;; Postgres unreserved words but may have meaning | |
1649 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil "a" | |
1650 | "abs" "absent" "according" "ada" "alias" "allocate" "are" "array_agg" | |
1651 | "asensitive" "atomic" "attribute" "attributes" "avg" "base64" | |
1652 | "bernoulli" "bit_length" "bitvar" "blob" "blocked" "bom" "breadth" "c" | |
1653 | "call" "cardinality" "catalog_name" "ceil" "ceiling" "char_length" | |
1654 | "character_length" "character_set_catalog" "character_set_name" | |
1655 | "character_set_schema" "characters" "checked" "class_origin" "clob" | |
1656 | "cobol" "collation" "collation_catalog" "collation_name" | |
1657 | "collation_schema" "collect" "column_name" "columns" | |
1658 | "command_function" "command_function_code" "completion" "condition" | |
1659 | "condition_number" "connect" "connection_name" "constraint_catalog" | |
1660 | "constraint_name" "constraint_schema" "constructor" "contains" | |
1661 | "control" "convert" "corr" "corresponding" "count" "covar_pop" | |
1662 | "covar_samp" "cube" "cume_dist" "current_default_transform_group" | |
1663 | "current_path" "current_transform_group_for_type" "cursor_name" | |
1664 | "datalink" "datetime_interval_code" "datetime_interval_precision" "db" | |
1665 | "defined" "degree" "dense_rank" "depth" "deref" "derived" "describe" | |
1666 | "descriptor" "destroy" "destructor" "deterministic" "diagnostics" | |
1667 | "disconnect" "dispatch" "dlnewcopy" "dlpreviouscopy" "dlurlcomplete" | |
1668 | "dlurlcompleteonly" "dlurlcompletewrite" "dlurlpath" "dlurlpathonly" | |
1669 | "dlurlpathwrite" "dlurlscheme" "dlurlserver" "dlvalue" "dynamic" | |
1670 | "dynamic_function" "dynamic_function_code" "element" "empty" | |
1671 | "end-exec" "equals" "every" "exception" "exec" "existing" "exp" "file" | |
1672 | "filter" "final" "first_value" "flag" "floor" "fortran" "found" "free" | |
1673 | "fs" "fusion" "g" "general" "generated" "get" "go" "goto" "grouping" | |
1674 | "hex" "hierarchy" "host" "id" "ignore" "implementation" "import" | |
1675 | "indent" "indicator" "infix" "initialize" "instance" "instantiable" | |
1676 | "integrity" "intersection" "iterate" "k" "key_member" "key_type" "lag" | |
1677 | "last_value" "lateral" "lead" "length" "less" "library" "like_regex" | |
1678 | "link" "ln" "locator" "lower" "m" "map" "matched" "max" | |
1679 | "max_cardinality" "member" "merge" "message_length" | |
1680 | "message_octet_length" "message_text" "method" "min" "mod" "modifies" | |
1681 | "modify" "module" "more" "multiset" "mumps" "namespace" "nclob" | |
1682 | "nesting" "new" "nfc" "nfd" "nfkc" "nfkd" "nil" "normalize" | |
1683 | "normalized" "nth_value" "ntile" "nullable" "number" | |
1684 | "occurrences_regex" "octet_length" "octets" "old" "open" "operation" | |
1685 | "ordering" "ordinality" "others" "output" "overriding" "p" "pad" | |
1686 | "parameter" "parameter_mode" "parameter_name" | |
1687 | "parameter_ordinal_position" "parameter_specific_catalog" | |
1688 | "parameter_specific_name" "parameter_specific_schema" "parameters" | |
1689 | "pascal" "passing" "passthrough" "percent_rank" "percentile_cont" | |
1690 | "percentile_disc" "permission" "pli" "position_regex" "postfix" | |
1691 | "power" "prefix" "preorder" "public" "rank" "reads" "recovery" "ref" | |
1692 | "referencing" "regr_avgx" "regr_avgy" "regr_count" "regr_intercept" | |
1693 | "regr_r2" "regr_slope" "regr_sxx" "regr_sxy" "regr_syy" "requiring" | |
1694 | "respect" "restore" "result" "return" "returned_cardinality" | |
1695 | "returned_length" "returned_octet_length" "returned_sqlstate" "rollup" | |
1696 | "routine" "routine_catalog" "routine_name" "routine_schema" | |
1697 | "row_count" "row_number" "scale" "schema_name" "scope" "scope_catalog" | |
1698 | "scope_name" "scope_schema" "section" "selective" "self" "sensitive" | |
1699 | "server_name" "sets" "size" "source" "space" "specific" | |
1700 | "specific_name" "specifictype" "sql" "sqlcode" "sqlerror" | |
1701 | "sqlexception" "sqlstate" "sqlwarning" "sqrt" "state" "static" | |
1702 | "stddev_pop" "stddev_samp" "structure" "style" "subclass_origin" | |
1703 | "sublist" "submultiset" "substring_regex" "sum" "system_user" "t" | |
1704 | "table_name" "tablesample" "terminate" "than" "ties" "timezone_hour" | |
1705 | "timezone_minute" "token" "top_level_count" "transaction_active" | |
1706 | "transactions_committed" "transactions_rolled_back" "transform" | |
1707 | "transforms" "translate" "translate_regex" "translation" | |
1708 | "trigger_catalog" "trigger_name" "trigger_schema" "trim_array" | |
1709 | "uescape" "under" "unlink" "unnamed" "unnest" "untyped" "upper" "uri" | |
1710 | "usage" "user_defined_type_catalog" "user_defined_type_code" | |
1711 | "user_defined_type_name" "user_defined_type_schema" "var_pop" | |
1712 | "var_samp" "varbinary" "variable" "whenever" "width_bucket" "within" | |
1713 | "xmlagg" "xmlbinary" "xmlcast" "xmlcomment" "xmldeclaration" | |
1714 | "xmldocument" "xmlexists" "xmliterate" "xmlnamespaces" "xmlquery" | |
1715 | "xmlschema" "xmltable" "xmltext" "xmlvalidate" | |
1716 | ) | |
1717 | ||
1718 | ;; Postgres non-reserved words | |
7492acc9 | 1719 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil |
9250002f MM |
1720 | "abort" "absolute" "access" "action" "add" "admin" "after" "aggregate" |
1721 | "also" "alter" "always" "assertion" "assignment" "at" "backward" | |
1722 | "before" "begin" "between" "by" "cache" "called" "cascade" "cascaded" | |
1723 | "catalog" "chain" "characteristics" "checkpoint" "class" "close" | |
1724 | "cluster" "coalesce" "comment" "comments" "commit" "committed" | |
1725 | "configuration" "connection" "constraints" "content" "continue" | |
1726 | "conversion" "copy" "cost" "createdb" "createrole" "createuser" "csv" | |
1727 | "current" "cursor" "cycle" "data" "database" "day" "deallocate" "dec" | |
1728 | "declare" "defaults" "deferred" "definer" "delete" "delimiter" | |
1729 | "delimiters" "dictionary" "disable" "discard" "document" "domain" | |
1730 | "drop" "each" "enable" "encoding" "encrypted" "enum" "escape" | |
1731 | "exclude" "excluding" "exclusive" "execute" "exists" "explain" | |
1732 | "external" "extract" "family" "first" "float" "following" "force" | |
1733 | "forward" "function" "functions" "global" "granted" "greatest" | |
1734 | "handler" "header" "hold" "hour" "identity" "if" "immediate" | |
1735 | "immutable" "implicit" "including" "increment" "index" "indexes" | |
1736 | "inherit" "inherits" "inline" "inout" "input" "insensitive" "insert" | |
1737 | "instead" "invoker" "isolation" "key" "language" "large" "last" | |
1738 | "lc_collate" "lc_ctype" "least" "level" "listen" "load" "local" | |
1739 | "location" "lock" "login" "mapping" "match" "maxvalue" "minute" | |
1740 | "minvalue" "mode" "month" "move" "name" "names" "national" "nchar" | |
1741 | "next" "no" "nocreatedb" "nocreaterole" "nocreateuser" "noinherit" | |
1742 | "nologin" "none" "nosuperuser" "nothing" "notify" "nowait" "nullif" | |
1743 | "nulls" "object" "of" "oids" "operator" "option" "options" "out" | |
1744 | "overlay" "owned" "owner" "parser" "partial" "partition" "password" | |
1745 | "plans" "position" "preceding" "prepare" "prepared" "preserve" "prior" | |
1746 | "privileges" "procedural" "procedure" "quote" "range" "read" | |
1747 | "reassign" "recheck" "recursive" "reindex" "relative" "release" | |
1748 | "rename" "repeatable" "replace" "replica" "reset" "restart" "restrict" | |
1749 | "returns" "revoke" "role" "rollback" "row" "rows" "rule" "savepoint" | |
1750 | "schema" "scroll" "search" "second" "security" "sequence" "sequences" | |
1751 | "serializable" "server" "session" "set" "setof" "share" "show" | |
1752 | "simple" "stable" "standalone" "start" "statement" "statistics" | |
1753 | "stdin" "stdout" "storage" "strict" "strip" "substring" "superuser" | |
1754 | "sysid" "system" "tables" "tablespace" "temp" "template" "temporary" | |
1755 | "transaction" "treat" "trigger" "trim" "truncate" "trusted" "type" | |
1756 | "unbounded" "uncommitted" "unencrypted" "unknown" "unlisten" "until" | |
1757 | "update" "vacuum" "valid" "validator" "value" "values" "version" | |
1758 | "view" "volatile" "whitespace" "work" "wrapper" "write" | |
1759 | "xmlattributes" "xmlconcat" "xmlelement" "xmlforest" "xmlparse" | |
1760 | "xmlpi" "xmlroot" "xmlserialize" "year" "yes" | |
7492acc9 | 1761 | ) |
9250002f | 1762 | |
7492acc9 MM |
1763 | ;; Postgres Reserved |
1764 | (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
9250002f MM |
1765 | "all" "analyse" "analyze" "and" "any" "array" "asc" "as" "asymmetric" |
1766 | "authorization" "binary" "both" "case" "cast" "check" "collate" | |
1767 | "column" "concurrently" "constraint" "create" "cross" | |
1768 | "current_catalog" "current_date" "current_role" "current_schema" | |
1769 | "current_time" "current_timestamp" "current_user" "default" | |
1770 | "deferrable" "desc" "distinct" "do" "else" "end" "except" "false" | |
1771 | "fetch" "foreign" "for" "freeze" "from" "full" "grant" "group" | |
1772 | "having" "ilike" "initially" "inner" "in" "intersect" "into" "isnull" | |
1773 | "is" "join" "leading" "left" "like" "limit" "localtime" | |
1774 | "localtimestamp" "natural" "notnull" "not" "null" "off" "offset" | |
1775 | "only" "on" "order" "or" "outer" "overlaps" "over" "placing" "primary" | |
1776 | "references" "returning" "right" "select" "session_user" "similar" | |
1777 | "some" "symmetric" "table" "then" "to" "trailing" "true" "union" | |
1778 | "unique" "user" "using" "variadic" "verbose" "when" "where" "window" | |
1779 | "with" | |
7492acc9 | 1780 | ) |
9fd8cb36 | 1781 | |
7492acc9 MM |
1782 | ;; Postgres Data Types |
1783 | (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
9250002f MM |
1784 | "bigint" "bigserial" "bit" "bool" "boolean" "box" "bytea" "char" |
1785 | "character" "cidr" "circle" "date" "decimal" "double" "float4" | |
1786 | "float8" "inet" "int" "int2" "int4" "int8" "integer" "interval" "line" | |
1787 | "lseg" "macaddr" "money" "numeric" "path" "point" "polygon" | |
1788 | "precision" "real" "serial" "serial4" "serial8" "smallint" "text" | |
1789 | "time" "timestamp" "timestamptz" "timetz" "tsquery" "tsvector" | |
1790 | "txid_snapshot" "uuid" "varbit" "varchar" "varying" "without" | |
1791 | "xml" "zone" | |
9fd8cb36 SM |
1792 | ))) |
1793 | ||
78024f88 | 1794 | "Postgres SQL keywords used by font-lock. |
f4df536d JB |
1795 | |
1796 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1797 | regular expressions are created during compilation by calling the | |
78024f88 | 1798 | function `regexp-opt'. Therefore, take a look at the source before |
063c6324 | 1799 | you define your own `sql-mode-postgres-font-lock-keywords'.") |
f4df536d | 1800 | |
78024f88 | 1801 | (defvar sql-mode-linter-font-lock-keywords |
7492acc9 MM |
1802 | (eval-when-compile |
1803 | (list | |
1804 | ;; Linter Keywords | |
1805 | (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
f4df536d JB |
1806 | "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel" |
1807 | "committed" "count" "countblob" "cross" "current" "data" "database" | |
1808 | "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred" | |
1809 | "denied" "description" "device" "difference" "directory" "error" | |
1810 | "escape" "euc" "exclusive" "external" "extfile" "false" "file" | |
1811 | "filename" "filesize" "filetime" "filter" "findblob" "first" "foreign" | |
1812 | "full" "fuzzy" "global" "granted" "ignore" "immediate" "increment" | |
1813 | "indexes" "indexfile" "indexfiles" "indextime" "initial" "integrity" | |
1814 | "internal" "key" "last_autoinc" "last_rowid" "limit" "linter" | |
1815 | "linter_file_device" "linter_file_size" "linter_name_length" "ln" | |
1816 | "local" "login" "maxisn" "maxrow" "maxrowid" "maxvalue" "message" | |
1817 | "minvalue" "module" "names" "national" "natural" "new" "new_table" | |
1818 | "no" "node" "noneuc" "nulliferror" "numbers" "off" "old" "old_table" | |
1819 | "only" "operation" "optimistic" "option" "page" "partially" "password" | |
1820 | "phrase" "plan" "precision" "primary" "priority" "privileges" | |
1821 | "proc_info_size" "proc_par_name_len" "protocol" "quant" "range" "raw" | |
1822 | "read" "record" "records" "references" "remote" "rename" "replication" | |
1823 | "restart" "rewrite" "root" "row" "rule" "savepoint" "security" | |
1824 | "sensitive" "sequence" "serializable" "server" "since" "size" "some" | |
1825 | "startup" "statement" "station" "success" "sys_guid" "tables" "test" | |
1826 | "timeout" "trace" "transaction" "translation" "trigger" | |
1827 | "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown" | |
1828 | "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes" | |
1829 | "wait" "windows_code" "workspace" "write" "xml" | |
7492acc9 | 1830 | ) |
78024f88 | 1831 | |
7492acc9 MM |
1832 | ;; Linter Reserved |
1833 | (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
f4df536d JB |
1834 | "access" "action" "add" "address" "after" "all" "alter" "always" "and" |
1835 | "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit" | |
1836 | "aud_obj_name_len" "backup" "base" "before" "between" "blobfile" | |
1837 | "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check" | |
1838 | "clear" "close" "column" "comment" "commit" "connect" "contains" | |
1839 | "correct" "create" "delete" "desc" "disable" "disconnect" "distinct" | |
1840 | "drop" "each" "ef" "else" "enable" "end" "event" "except" "exclude" | |
1841 | "execute" "exists" "extract" "fetch" "finish" "for" "from" "get" | |
1842 | "grant" "group" "having" "identified" "in" "index" "inner" "insert" | |
1843 | "instead" "intersect" "into" "is" "isolation" "join" "left" "level" | |
1844 | "like" "lock" "mode" "modify" "not" "nowait" "null" "of" "on" "open" | |
1845 | "or" "order" "outer" "owner" "press" "prior" "procedure" "public" | |
1846 | "purge" "rebuild" "resource" "restrict" "revoke" "right" "role" | |
1847 | "rollback" "rownum" "select" "session" "set" "share" "shutdown" | |
1848 | "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then" | |
1849 | "to" "union" "unique" "unlock" "until" "update" "using" "values" | |
1850 | "view" "when" "where" "with" "without" | |
7492acc9 | 1851 | ) |
78024f88 | 1852 | |
7492acc9 MM |
1853 | ;; Linter Functions |
1854 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
f4df536d JB |
1855 | "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime" |
1856 | "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw" | |
1857 | "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log" | |
1858 | "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl" | |
1859 | "octet_length" "power" "rand" "rawtohex" "repeat_string" | |
1860 | "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex" | |
1861 | "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date" | |
1862 | "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode" | |
1863 | "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap" | |
1864 | "instr" "least" "multime" "replace" "width" | |
7492acc9 | 1865 | ) |
78024f88 | 1866 | |
7492acc9 MM |
1867 | ;; Linter Data Types |
1868 | (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
1869 | "bigint" "bitmap" "blob" "boolean" "char" "character" "date" | |
1870 | "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar" | |
1871 | "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte" | |
1872 | "cursor" "long" | |
1873 | ))) | |
78024f88 AS |
1874 | |
1875 | "Linter SQL keywords used by font-lock. | |
f4df536d | 1876 | |
78024f88 AS |
1877 | This variable is used by `sql-mode' and `sql-interactive-mode'. The |
1878 | regular expressions are created during compilation by calling the | |
1879 | function `regexp-opt'.") | |
1880 | ||
1881 | (defvar sql-mode-ms-font-lock-keywords | |
7492acc9 MM |
1882 | (eval-when-compile |
1883 | (list | |
1884 | ;; MS isql/osql Commands | |
1885 | (cons | |
1886 | (concat | |
1887 | "^\\(?:\\(?:set\\s-+\\(?:" | |
1888 | (regexp-opt '( | |
1889 | "datefirst" "dateformat" "deadlock_priority" "lock_timeout" | |
1890 | "concat_null_yields_null" "cursor_close_on_commit" | |
1891 | "disable_def_cnst_chk" "fips_flagger" "identity_insert" "language" | |
1892 | "offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly" | |
1893 | "nocount" "noexec" "numeric_roundabort" "parseonly" | |
1894 | "query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults" | |
1895 | "ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding" | |
1896 | "ansi_warnings" "forceplan" "showplan_all" "showplan_text" | |
1897 | "statistics" "implicit_transactions" "remote_proc_transactions" | |
1898 | "transaction" "xact_abort" | |
1899 | ) t) | |
1900 | "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$") | |
1901 | 'font-lock-doc-face) | |
1902 | ||
1903 | ;; MS Reserved | |
1904 | (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
78024f88 AS |
1905 | "absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization" |
1906 | "avg" "backup" "begin" "between" "break" "browse" "bulk" "by" | |
1907 | "cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce" | |
1908 | "column" "commit" "committed" "compute" "confirm" "constraint" | |
1909 | "contains" "containstable" "continue" "controlrow" "convert" "count" | |
1910 | "create" "cross" "current" "current_date" "current_time" | |
9fd8cb36 SM |
1911 | "current_timestamp" "current_user" "database" "deallocate" "declare" |
1912 | "default" "delete" "deny" "desc" "disk" "distinct" "distributed" | |
1913 | "double" "drop" "dummy" "dump" "else" "end" "errlvl" "errorexit" | |
1914 | "escape" "except" "exec" "execute" "exists" "exit" "fetch" "file" | |
1915 | "fillfactor" "first" "floppy" "for" "foreign" "freetext" | |
78024f88 AS |
1916 | "freetexttable" "from" "full" "goto" "grant" "group" "having" |
1917 | "holdlock" "identity" "identity_insert" "identitycol" "if" "in" | |
1918 | "index" "inner" "insert" "intersect" "into" "is" "isolation" "join" | |
1919 | "key" "kill" "last" "left" "level" "like" "lineno" "load" "max" "min" | |
1920 | "mirrorexit" "national" "next" "nocheck" "nolock" "nonclustered" "not" | |
1921 | "null" "nullif" "of" "off" "offsets" "on" "once" "only" "open" | |
1922 | "opendatasource" "openquery" "openrowset" "option" "or" "order" | |
1923 | "outer" "output" "over" "paglock" "percent" "perm" "permanent" "pipe" | |
1924 | "plan" "precision" "prepare" "primary" "print" "prior" "privileges" | |
1925 | "proc" "procedure" "processexit" "public" "raiserror" "read" | |
1926 | "readcommitted" "readpast" "readtext" "readuncommitted" "reconfigure" | |
1927 | "references" "relative" "repeatable" "repeatableread" "replication" | |
1928 | "restore" "restrict" "return" "revoke" "right" "rollback" "rowcount" | |
1929 | "rowguidcol" "rowlock" "rule" "save" "schema" "select" "serializable" | |
1930 | "session_user" "set" "shutdown" "some" "statistics" "sum" | |
1931 | "system_user" "table" "tablock" "tablockx" "tape" "temp" "temporary" | |
1932 | "textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate" | |
1933 | "tsequal" "uncommitted" "union" "unique" "update" "updatetext" | |
1934 | "updlock" "use" "user" "values" "view" "waitfor" "when" "where" | |
9fd8cb36 SM |
1935 | "while" "with" "work" "writetext" "collate" "function" "openxml" |
1936 | "returns" | |
7492acc9 | 1937 | ) |
78024f88 | 1938 | |
7492acc9 MM |
1939 | ;; MS Functions |
1940 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
78024f88 AS |
1941 | "@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts" |
1942 | "@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy" | |
1943 | "@@langid" "@@language" "@@lock_timeout" "@@max_connections" | |
1944 | "@@max_precision" "@@nestlevel" "@@options" "@@pack_received" | |
1945 | "@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount" | |
1946 | "@@servername" "@@servicename" "@@spid" "@@textsize" "@@timeticks" | |
1947 | "@@total_errors" "@@total_read" "@@total_write" "@@trancount" | |
1948 | "@@version" "abs" "acos" "and" "app_name" "ascii" "asin" "atan" "atn2" | |
1949 | "avg" "case" "cast" "ceiling" "char" "charindex" "coalesce" | |
1950 | "col_length" "col_name" "columnproperty" "containstable" "convert" | |
1951 | "cos" "cot" "count" "current_timestamp" "current_user" "cursor_status" | |
1952 | "databaseproperty" "datalength" "dateadd" "datediff" "datename" | |
1953 | "datepart" "day" "db_id" "db_name" "degrees" "difference" "exp" | |
1954 | "file_id" "file_name" "filegroup_id" "filegroup_name" | |
1955 | "filegroupproperty" "fileproperty" "floor" "formatmessage" | |
1956 | "freetexttable" "fulltextcatalogproperty" "fulltextserviceproperty" | |
1957 | "getansinull" "getdate" "grouping" "host_id" "host_name" "ident_incr" | |
1958 | "ident_seed" "identity" "index_col" "indexproperty" "is_member" | |
1959 | "is_srvrolemember" "isdate" "isnull" "isnumeric" "left" "len" "log" | |
1960 | "log10" "lower" "ltrim" "max" "min" "month" "nchar" "newid" "nullif" | |
1961 | "object_id" "object_name" "objectproperty" "openquery" "openrowset" | |
1962 | "parsename" "patindex" "patindex" "permissions" "pi" "power" | |
1963 | "quotename" "radians" "rand" "replace" "replicate" "reverse" "right" | |
1964 | "round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt" | |
1965 | "square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum" | |
1966 | "suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan" | |
1967 | "textptr" "textvalid" "typeproperty" "unicode" "upper" "user" | |
1968 | "user_id" "user_name" "var" "varp" "year" | |
7492acc9 | 1969 | ) |
78024f88 | 1970 | |
7492acc9 MM |
1971 | ;; MS Variables |
1972 | '("\\b@[a-zA-Z0-9_]*\\b" . font-lock-variable-name-face) | |
78024f88 | 1973 | |
7492acc9 MM |
1974 | ;; MS Types |
1975 | (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
1976 | "binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal" | |
1977 | "double" "float" "image" "int" "integer" "money" "national" "nchar" | |
1978 | "ntext" "numeric" "numeric" "nvarchar" "precision" "real" | |
1979 | "smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint" | |
1980 | "uniqueidentifier" "varbinary" "varchar" "varying" | |
1981 | ))) | |
78024f88 AS |
1982 | |
1983 | "Microsoft SQLServer SQL keywords used by font-lock. | |
1984 | ||
1985 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1986 | regular expressions are created during compilation by calling the | |
1987 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 | 1988 | you define your own `sql-mode-ms-font-lock-keywords'.") |
78024f88 | 1989 | |
9fd8cb36 | 1990 | (defvar sql-mode-sybase-font-lock-keywords nil |
78024f88 AS |
1991 | "Sybase SQL keywords used by font-lock. |
1992 | ||
1993 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1994 | regular expressions are created during compilation by calling the | |
1995 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 | 1996 | you define your own `sql-mode-sybase-font-lock-keywords'.") |
78024f88 | 1997 | |
9fd8cb36 | 1998 | (defvar sql-mode-informix-font-lock-keywords nil |
78024f88 AS |
1999 | "Informix SQL keywords used by font-lock. |
2000 | ||
2001 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
2002 | regular expressions are created during compilation by calling the | |
2003 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 | 2004 | you define your own `sql-mode-informix-font-lock-keywords'.") |
78024f88 | 2005 | |
9fd8cb36 | 2006 | (defvar sql-mode-interbase-font-lock-keywords nil |
78024f88 AS |
2007 | "Interbase SQL keywords used by font-lock. |
2008 | ||
2009 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
2010 | regular expressions are created during compilation by calling the | |
2011 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 | 2012 | you define your own `sql-mode-interbase-font-lock-keywords'.") |
78024f88 | 2013 | |
9fd8cb36 | 2014 | (defvar sql-mode-ingres-font-lock-keywords nil |
78024f88 AS |
2015 | "Ingres SQL keywords used by font-lock. |
2016 | ||
2017 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
2018 | regular expressions are created during compilation by calling the | |
2019 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 | 2020 | you define your own `sql-mode-interbase-font-lock-keywords'.") |
78024f88 | 2021 | |
9fd8cb36 | 2022 | (defvar sql-mode-solid-font-lock-keywords nil |
78024f88 AS |
2023 | "Solid SQL keywords used by font-lock. |
2024 | ||
2025 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
2026 | regular expressions are created during compilation by calling the | |
2027 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 | 2028 | you define your own `sql-mode-solid-font-lock-keywords'.") |
78024f88 | 2029 | |
9fd8cb36 | 2030 | (defvar sql-mode-mysql-font-lock-keywords |
7492acc9 MM |
2031 | (eval-when-compile |
2032 | (list | |
2033 | ;; MySQL Functions | |
2034 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
9fd8cb36 SM |
2035 | "ascii" "avg" "bdmpolyfromtext" "bdmpolyfromwkb" "bdpolyfromtext" |
2036 | "bdpolyfromwkb" "benchmark" "bin" "bit_and" "bit_length" "bit_or" | |
2037 | "bit_xor" "both" "cast" "char_length" "character_length" "coalesce" | |
2038 | "concat" "concat_ws" "connection_id" "conv" "convert" "count" | |
2039 | "curdate" "current_date" "current_time" "current_timestamp" "curtime" | |
2040 | "elt" "encrypt" "export_set" "field" "find_in_set" "found_rows" "from" | |
2041 | "geomcollfromtext" "geomcollfromwkb" "geometrycollectionfromtext" | |
2042 | "geometrycollectionfromwkb" "geometryfromtext" "geometryfromwkb" | |
2043 | "geomfromtext" "geomfromwkb" "get_lock" "group_concat" "hex" "ifnull" | |
2044 | "instr" "interval" "isnull" "last_insert_id" "lcase" "leading" | |
2045 | "length" "linefromtext" "linefromwkb" "linestringfromtext" | |
2046 | "linestringfromwkb" "load_file" "locate" "lower" "lpad" "ltrim" | |
2047 | "make_set" "master_pos_wait" "max" "mid" "min" "mlinefromtext" | |
2048 | "mlinefromwkb" "mpointfromtext" "mpointfromwkb" "mpolyfromtext" | |
2049 | "mpolyfromwkb" "multilinestringfromtext" "multilinestringfromwkb" | |
2050 | "multipointfromtext" "multipointfromwkb" "multipolygonfromtext" | |
2051 | "multipolygonfromwkb" "now" "nullif" "oct" "octet_length" "ord" | |
2052 | "pointfromtext" "pointfromwkb" "polyfromtext" "polyfromwkb" | |
2053 | "polygonfromtext" "polygonfromwkb" "position" "quote" "rand" | |
2054 | "release_lock" "repeat" "replace" "reverse" "rpad" "rtrim" "soundex" | |
2055 | "space" "std" "stddev" "substring" "substring_index" "sum" "sysdate" | |
2056 | "trailing" "trim" "ucase" "unix_timestamp" "upper" "user" "variance" | |
7492acc9 | 2057 | ) |
9fd8cb36 | 2058 | |
7492acc9 MM |
2059 | ;; MySQL Keywords |
2060 | (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
9fd8cb36 SM |
2061 | "action" "add" "after" "against" "all" "alter" "and" "as" "asc" |
2062 | "auto_increment" "avg_row_length" "bdb" "between" "by" "cascade" | |
2063 | "case" "change" "character" "check" "checksum" "close" "collate" | |
2064 | "collation" "column" "columns" "comment" "committed" "concurrent" | |
2065 | "constraint" "create" "cross" "data" "database" "default" | |
2066 | "delay_key_write" "delayed" "delete" "desc" "directory" "disable" | |
2067 | "distinct" "distinctrow" "do" "drop" "dumpfile" "duplicate" "else" | |
2068 | "enable" "enclosed" "end" "escaped" "exists" "fields" "first" "for" | |
2069 | "force" "foreign" "from" "full" "fulltext" "global" "group" "handler" | |
2070 | "having" "heap" "high_priority" "if" "ignore" "in" "index" "infile" | |
2071 | "inner" "insert" "insert_method" "into" "is" "isam" "isolation" "join" | |
2072 | "key" "keys" "last" "left" "level" "like" "limit" "lines" "load" | |
2073 | "local" "lock" "low_priority" "match" "max_rows" "merge" "min_rows" | |
2074 | "mode" "modify" "mrg_myisam" "myisam" "natural" "next" "no" "not" | |
2075 | "null" "offset" "oj" "on" "open" "optionally" "or" "order" "outer" | |
2076 | "outfile" "pack_keys" "partial" "password" "prev" "primary" | |
2077 | "procedure" "quick" "raid0" "raid_type" "read" "references" "rename" | |
2078 | "repeatable" "restrict" "right" "rollback" "rollup" "row_format" | |
2079 | "savepoint" "select" "separator" "serializable" "session" "set" | |
2080 | "share" "show" "sql_big_result" "sql_buffer_result" "sql_cache" | |
2081 | "sql_calc_found_rows" "sql_no_cache" "sql_small_result" "starting" | |
2082 | "straight_join" "striped" "table" "tables" "temporary" "terminated" | |
2083 | "then" "to" "transaction" "truncate" "type" "uncommitted" "union" | |
2084 | "unique" "unlock" "update" "use" "using" "values" "when" "where" | |
2085 | "with" "write" "xor" | |
7492acc9 | 2086 | ) |
9fd8cb36 | 2087 | |
7492acc9 MM |
2088 | ;; MySQL Data Types |
2089 | (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
9fd8cb36 SM |
2090 | "bigint" "binary" "bit" "blob" "bool" "boolean" "char" "curve" "date" |
2091 | "datetime" "dec" "decimal" "double" "enum" "fixed" "float" "geometry" | |
2092 | "geometrycollection" "int" "integer" "line" "linearring" "linestring" | |
2093 | "longblob" "longtext" "mediumblob" "mediumint" "mediumtext" | |
2094 | "multicurve" "multilinestring" "multipoint" "multipolygon" | |
2095 | "multisurface" "national" "numeric" "point" "polygon" "precision" | |
2096 | "real" "smallint" "surface" "text" "time" "timestamp" "tinyblob" | |
2097 | "tinyint" "tinytext" "unsigned" "varchar" "year" "year2" "year4" | |
2098 | "zerofill" | |
2099 | ))) | |
2100 | ||
78024f88 AS |
2101 | "MySQL SQL keywords used by font-lock. |
2102 | ||
2103 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
2104 | regular expressions are created during compilation by calling the | |
2105 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 | 2106 | you define your own `sql-mode-mysql-font-lock-keywords'.") |
78024f88 | 2107 | |
b93d4f22 MM |
2108 | (defvar sql-mode-sqlite-font-lock-keywords |
2109 | (eval-when-compile | |
2110 | (list | |
9250002f MM |
2111 | ;; SQLite commands |
2112 | '("^[.].*$" . font-lock-doc-face) | |
2113 | ||
b93d4f22 MM |
2114 | ;; SQLite Keyword |
2115 | (sql-font-lock-keywords-builder 'font-lock-keyword-face nil | |
2116 | "abort" "action" "add" "after" "all" "alter" "analyze" "and" "as" | |
2117 | "asc" "attach" "autoincrement" "before" "begin" "between" "by" | |
2118 | "cascade" "case" "cast" "check" "collate" "column" "commit" "conflict" | |
3bd2cfef MM |
2119 | "constraint" "create" "cross" "database" "default" "deferrable" |
2120 | "deferred" "delete" "desc" "detach" "distinct" "drop" "each" "else" | |
2121 | "end" "escape" "except" "exclusive" "exists" "explain" "fail" "for" | |
b93d4f22 MM |
2122 | "foreign" "from" "full" "glob" "group" "having" "if" "ignore" |
2123 | "immediate" "in" "index" "indexed" "initially" "inner" "insert" | |
2124 | "instead" "intersect" "into" "is" "isnull" "join" "key" "left" "like" | |
2125 | "limit" "match" "natural" "no" "not" "notnull" "null" "of" "offset" | |
2126 | "on" "or" "order" "outer" "plan" "pragma" "primary" "query" "raise" | |
2127 | "references" "regexp" "reindex" "release" "rename" "replace" | |
2128 | "restrict" "right" "rollback" "row" "savepoint" "select" "set" "table" | |
2129 | "temp" "temporary" "then" "to" "transaction" "trigger" "union" | |
2130 | "unique" "update" "using" "vacuum" "values" "view" "virtual" "when" | |
2131 | "where" | |
2132 | ) | |
2133 | ;; SQLite Data types | |
2134 | (sql-font-lock-keywords-builder 'font-lock-type-face nil | |
2135 | "int" "integer" "tinyint" "smallint" "mediumint" "bigint" "unsigned" | |
3bd2cfef | 2136 | "big" "int2" "int8" "character" "varchar" "varying" "nchar" "native" |
b93d4f22 | 2137 | "nvarchar" "text" "clob" "blob" "real" "double" "precision" "float" |
3bd2cfef | 2138 | "numeric" "number" "decimal" "boolean" "date" "datetime" |
b93d4f22 MM |
2139 | ) |
2140 | ;; SQLite Functions | |
2141 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | |
2142 | ;; Core functions | |
2143 | "abs" "changes" "coalesce" "glob" "ifnull" "hex" "last_insert_rowid" | |
2144 | "length" "like" "load_extension" "lower" "ltrim" "max" "min" "nullif" | |
2145 | "quote" "random" "randomblob" "replace" "round" "rtrim" "soundex" | |
2146 | "sqlite_compileoption_get" "sqlite_compileoption_used" | |
2147 | "sqlite_source_id" "sqlite_version" "substr" "total_changes" "trim" | |
2148 | "typeof" "upper" "zeroblob" | |
2149 | ;; Date/time functions | |
2150 | "time" "julianday" "strftime" | |
3bd2cfef | 2151 | "current_date" "current_time" "current_timestamp" |
b93d4f22 MM |
2152 | ;; Aggregate functions |
2153 | "avg" "count" "group_concat" "max" "min" "sum" "total" | |
2154 | ))) | |
2155 | ||
78024f88 AS |
2156 | "SQLite SQL keywords used by font-lock. |
2157 | ||
2158 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
2159 | regular expressions are created during compilation by calling the | |
2160 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 | 2161 | you define your own `sql-mode-sqlite-font-lock-keywords'.") |
78024f88 | 2162 | |
9fd8cb36 | 2163 | (defvar sql-mode-db2-font-lock-keywords nil |
78024f88 AS |
2164 | "DB2 SQL keywords used by font-lock. |
2165 | ||
2166 | This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
2167 | regular expressions are created during compilation by calling the | |
2168 | function `regexp-opt'. Therefore, take a look at the source before | |
063c6324 | 2169 | you define your own `sql-mode-db2-font-lock-keywords'.") |
78024f88 AS |
2170 | |
2171 | (defvar sql-mode-font-lock-keywords nil | |
95e4b2ef RS |
2172 | "SQL keywords used by font-lock. |
2173 | ||
78024f88 AS |
2174 | Setting this variable directly no longer has any affect. Use |
2175 | `sql-product' and `sql-add-product-keywords' to control the | |
063c6324 | 2176 | highlighting rules in SQL mode.") |
78024f88 AS |
2177 | |
2178 | \f | |
2179 | ||
2180 | ;;; SQL Product support functions | |
2181 | ||
74790210 MM |
2182 | (defun sql-read-product (prompt &optional initial) |
2183 | "Read a valid SQL product." | |
2184 | (let ((init (or (and initial (symbol-name initial)) "ansi"))) | |
2185 | (intern (completing-read | |
2186 | prompt | |
2187 | (mapcar (lambda (info) (symbol-name (car info))) | |
2188 | sql-product-alist) | |
2189 | nil 'require-match | |
2190 | init 'sql-product-history init)))) | |
2191 | ||
7492acc9 MM |
2192 | (defun sql-add-product (product display &rest plist) |
2193 | "Add support for a database product in `sql-mode'. | |
2194 | ||
2195 | Add PRODUCT to `sql-product-alist' which enables `sql-mode' to | |
2196 | properly support syntax highlighting and interactive interaction. | |
2197 | DISPLAY is the name of the SQL product that will appear in the | |
2198 | menu bar and in messages. PLIST initializes the product | |
2199 | configuration." | |
2200 | ||
2201 | ;; Don't do anything if the product is already supported | |
2202 | (if (assoc product sql-product-alist) | |
2203 | (message "Product `%s' is already defined" product) | |
2204 | ||
2205 | ;; Add product to the alist | |
2206 | (add-to-list 'sql-product-alist `((,product :name ,display . ,plist))) | |
2207 | ;; Add a menu item to the SQL->Product menu | |
2208 | (easy-menu-add-item sql-mode-menu '("Product") | |
2209 | ;; Each product is represented by a radio | |
2210 | ;; button with it's display name. | |
2211 | `[,display | |
d26b0ea9 | 2212 | (sql-set-product ',product) |
7492acc9 MM |
2213 | :style radio |
2214 | :selected (eq sql-product ',product)] | |
2215 | ;; Maintain the product list in | |
2216 | ;; (case-insensitive) alphabetic order of the | |
2217 | ;; display names. Loop thru each keymap item | |
2218 | ;; looking for an item whose display name is | |
2219 | ;; after this product's name. | |
2220 | (let ((next-item) | |
2221 | (down-display (downcase display))) | |
2222 | (map-keymap (lambda (k b) | |
2223 | (when (and (not next-item) | |
2224 | (string-lessp down-display | |
2225 | (downcase (cadr b)))) | |
2226 | (setq next-item k))) | |
2227 | (easy-menu-get-map sql-mode-menu '("Product"))) | |
2228 | next-item)) | |
2229 | product)) | |
2230 | ||
2231 | (defun sql-del-product (product) | |
2232 | "Remove support for PRODUCT in `sql-mode'." | |
2233 | ||
2234 | ;; Remove the menu item based on the display name | |
2235 | (easy-menu-remove-item sql-mode-menu '("Product") (sql-get-product-feature product :name)) | |
2236 | ;; Remove the product alist item | |
2237 | (setq sql-product-alist (assq-delete-all product sql-product-alist)) | |
2238 | nil) | |
2239 | ||
2240 | (defun sql-set-product-feature (product feature newvalue) | |
2241 | "Set FEATURE of database PRODUCT to NEWVALUE. | |
2242 | ||
2243 | The PRODUCT must be a symbol which identifies the database | |
2244 | product. The product must have already exist on the product | |
2245 | list. See `sql-add-product' to add new products. The FEATURE | |
2246 | argument must be a plist keyword accepted by | |
2247 | `sql-product-alist'." | |
2248 | ||
2249 | (let* ((p (assoc product sql-product-alist)) | |
2250 | (v (plist-get (cdr p) feature))) | |
2251 | (if p | |
2252 | (if (and | |
2253 | (member feature sql-indirect-features) | |
2254 | (symbolp v)) | |
2255 | (set v newvalue) | |
2256 | (setcdr p (plist-put (cdr p) feature newvalue))) | |
2257 | (message "`%s' is not a known product; use `sql-add-product' to add it first." product)))) | |
2258 | ||
30c4d8dc | 2259 | (defun sql-get-product-feature (product feature &optional fallback not-indirect) |
7492acc9 MM |
2260 | "Lookup FEATURE associated with a SQL PRODUCT. |
2261 | ||
2262 | If the FEATURE is nil for PRODUCT, and FALLBACK is specified, | |
2263 | then the FEATURE associated with the FALLBACK product is | |
2264 | returned. | |
78024f88 | 2265 | |
30c4d8dc MM |
2266 | If the FEATURE is in the list `sql-indirect-features', and the |
2267 | NOT-INDIRECT parameter is not set, then the value of the symbol | |
2268 | stored in the connect alist is returned. | |
2269 | ||
063c6324 | 2270 | See `sql-product-alist' for a list of products and supported features." |
7492acc9 MM |
2271 | (let* ((p (assoc product sql-product-alist)) |
2272 | (v (plist-get (cdr p) feature))) | |
2273 | ||
2274 | (if p | |
2275 | ;; If no value and fallback, lookup feature for fallback | |
2276 | (if (and (not v) | |
2277 | fallback | |
2278 | (not (eq product fallback))) | |
2279 | (sql-get-product-feature fallback feature) | |
2280 | ||
2281 | (if (and | |
2282 | (member feature sql-indirect-features) | |
30c4d8dc | 2283 | (not not-indirect) |
7492acc9 MM |
2284 | (symbolp v)) |
2285 | (symbol-value v) | |
2286 | v)) | |
d26b0ea9 MM |
2287 | (message "`%s' is not a known product; use `sql-add-product' to add it first." product) |
2288 | nil))) | |
78024f88 AS |
2289 | |
2290 | (defun sql-product-font-lock (keywords-only imenu) | |
c38762fd | 2291 | "Configure font-lock and imenu with product-specific settings. |
7492acc9 MM |
2292 | |
2293 | The KEYWORDS-ONLY flag is passed to font-lock to specify whether | |
2294 | only keywords should be hilighted and syntactic hilighting | |
2295 | skipped. The IMENU flag indicates whether `imenu-mode' should | |
2296 | also be configured." | |
2297 | ||
78024f88 AS |
2298 | (let |
2299 | ;; Get the product-specific syntax-alist. | |
2300 | ((syntax-alist | |
2301 | (append | |
7492acc9 | 2302 | (sql-get-product-feature sql-product :syntax-alist) |
78024f88 AS |
2303 | '((?_ . "w") (?. . "w"))))) |
2304 | ||
2305 | ;; Get the product-specific keywords. | |
175069ef SM |
2306 | (set (make-local-variable 'sql-mode-font-lock-keywords) |
2307 | (append | |
2308 | (unless (eq sql-product 'ansi) | |
2309 | (sql-get-product-feature sql-product :font-lock)) | |
2310 | ;; Always highlight ANSI keywords | |
2311 | (sql-get-product-feature 'ansi :font-lock) | |
2312 | ;; Fontify object names in CREATE, DROP and ALTER DDL | |
2313 | ;; statements | |
2314 | (list sql-mode-font-lock-object-name))) | |
78024f88 | 2315 | |
9a9069c9 | 2316 | ;; Setup font-lock. Force re-parsing of `font-lock-defaults'. |
7492acc9 | 2317 | (kill-local-variable 'font-lock-set-defaults) |
175069ef SM |
2318 | (set (make-local-variable 'font-lock-defaults) |
2319 | (list 'sql-mode-font-lock-keywords | |
2320 | keywords-only t syntax-alist)) | |
78024f88 | 2321 | |
9a9069c9 SM |
2322 | ;; Force font lock to reinitialize if it is already on |
2323 | ;; Otherwise, we can wait until it can be started. | |
2324 | (when (and (fboundp 'font-lock-mode) | |
7492acc9 | 2325 | (boundp 'font-lock-mode) |
9a9069c9 SM |
2326 | font-lock-mode) |
2327 | (font-lock-mode-internal nil) | |
2328 | (font-lock-mode-internal t)) | |
2329 | ||
2330 | (add-hook 'font-lock-mode-hook | |
2331 | (lambda () | |
2332 | ;; Provide defaults for new font-lock faces. | |
2333 | (defvar font-lock-builtin-face | |
2334 | (if (boundp 'font-lock-preprocessor-face) | |
2335 | font-lock-preprocessor-face | |
2336 | font-lock-keyword-face)) | |
2337 | (defvar font-lock-doc-face font-lock-string-face)) | |
2338 | nil t) | |
2339 | ||
78024f88 AS |
2340 | ;; Setup imenu; it needs the same syntax-alist. |
2341 | (when imenu | |
7492acc9 | 2342 | (setq imenu-syntax-alist syntax-alist)))) |
78024f88 AS |
2343 | |
2344 | ;;;###autoload | |
9fd8cb36 SM |
2345 | (defun sql-add-product-keywords (product keywords &optional append) |
2346 | "Add highlighting KEYWORDS for SQL PRODUCT. | |
2347 | ||
c38762fd | 2348 | PRODUCT should be a symbol, the name of a SQL product, such as |
9fd8cb36 SM |
2349 | `oracle'. KEYWORDS should be a list; see the variable |
2350 | `font-lock-keywords'. By default they are added at the beginning | |
2351 | of the current highlighting list. If optional argument APPEND is | |
2352 | `set', they are used to replace the current highlighting list. | |
2353 | If APPEND is any other non-nil value, they are added at the end | |
2354 | of the current highlighting list. | |
2355 | ||
2356 | For example: | |
2357 | ||
2358 | (sql-add-product-keywords 'ms | |
2359 | '((\"\\\\b\\\\w+_t\\\\b\" . font-lock-type-face))) | |
2360 | ||
2361 | adds a fontification pattern to fontify identifiers ending in | |
2362 | `_t' as data types." | |
2363 | ||
7492acc9 MM |
2364 | (let* ((sql-indirect-features nil) |
2365 | (font-lock-var (sql-get-product-feature product :font-lock)) | |
2366 | (old-val)) | |
2367 | ||
2368 | (setq old-val (symbol-value font-lock-var)) | |
2369 | (set font-lock-var | |
9fd8cb36 SM |
2370 | (if (eq append 'set) |
2371 | keywords | |
2372 | (if append | |
7492acc9 MM |
2373 | (append old-val keywords) |
2374 | (append keywords old-val)))))) | |
95e4b2ef | 2375 | |
5474c40f MM |
2376 | (defun sql-for-each-login (login-params body) |
2377 | "Iterates through login parameters and returns a list of results." | |
2378 | ||
2379 | (delq nil | |
2380 | (mapcar | |
2381 | (lambda (param) | |
2382 | (let ((token (or (and (listp param) (car param)) param)) | |
74790210 | 2383 | (plist (or (and (listp param) (cdr param)) nil))) |
5474c40f | 2384 | |
74790210 | 2385 | (funcall body token plist))) |
5474c40f MM |
2386 | login-params))) |
2387 | ||
95e4b2ef | 2388 | \f |
c0bbaf57 | 2389 | |
624ef9b3 GM |
2390 | ;;; Functions to switch highlighting |
2391 | ||
78024f88 | 2392 | (defun sql-highlight-product () |
c38762fd | 2393 | "Turn on the font highlighting for the SQL product selected." |
55659495 | 2394 | (when (derived-mode-p 'sql-mode) |
78024f88 AS |
2395 | ;; Setup font-lock |
2396 | (sql-product-font-lock nil t) | |
2397 | ||
78024f88 | 2398 | ;; Set the mode name to include the product. |
7492acc9 MM |
2399 | (setq mode-name (concat "SQL[" (or (sql-get-product-feature sql-product :name) |
2400 | (symbol-name sql-product)) "]")))) | |
78024f88 AS |
2401 | |
2402 | (defun sql-set-product (product) | |
c38762fd | 2403 | "Set `sql-product' to PRODUCT and enable appropriate highlighting." |
55659495 | 2404 | (interactive |
74790210 | 2405 | (list (sql-read-product "SQL product: "))) |
55659495 | 2406 | (if (stringp product) (setq product (intern product))) |
9fd8cb36 | 2407 | (when (not (assoc product sql-product-alist)) |
78024f88 AS |
2408 | (error "SQL product %s is not supported; treated as ANSI" product) |
2409 | (setq product 'ansi)) | |
2410 | ||
2411 | ;; Save product setting and fontify. | |
2412 | (setq sql-product product) | |
2413 | (sql-highlight-product)) | |
624ef9b3 GM |
2414 | \f |
2415 | ||
04231ab8 MB |
2416 | ;;; Compatibility functions |
2417 | ||
2418 | (if (not (fboundp 'comint-line-beginning-position)) | |
2419 | ;; comint-line-beginning-position is defined in Emacs 21 | |
2420 | (defun comint-line-beginning-position () | |
063c6324 | 2421 | "Return the buffer position of the beginning of the line, after any prompt. |
04231ab8 MB |
2422 | The prompt is assumed to be any text at the beginning of the line matching |
2423 | the regular expression `comint-prompt-regexp', a buffer local variable." | |
2424 | (save-excursion (comint-bol nil) (point)))) | |
2425 | ||
2426 | \f | |
95e4b2ef RS |
2427 | |
2428 | ;;; Small functions | |
2429 | ||
9ef3882f GM |
2430 | (defun sql-magic-go (arg) |
2431 | "Insert \"o\" and call `comint-send-input'. | |
2432 | `sql-electric-stuff' must be the symbol `go'." | |
2433 | (interactive "P") | |
2434 | (self-insert-command (prefix-numeric-value arg)) | |
2435 | (if (and (equal sql-electric-stuff 'go) | |
2436 | (save-excursion | |
3035b156 MB |
2437 | (comint-bol nil) |
2438 | (looking-at "go\\b"))) | |
9ef3882f GM |
2439 | (comint-send-input))) |
2440 | ||
2441 | (defun sql-magic-semicolon (arg) | |
2442 | "Insert semicolon and call `comint-send-input'. | |
2443 | `sql-electric-stuff' must be the symbol `semicolon'." | |
2444 | (interactive "P") | |
2445 | (self-insert-command (prefix-numeric-value arg)) | |
2446 | (if (equal sql-electric-stuff 'semicolon) | |
2447 | (comint-send-input))) | |
2448 | ||
95e4b2ef RS |
2449 | (defun sql-accumulate-and-indent () |
2450 | "Continue SQL statement on the next line." | |
2451 | (interactive) | |
f4df536d | 2452 | (if (fboundp 'comint-accumulate) |
9ef3882f GM |
2453 | (comint-accumulate) |
2454 | (newline)) | |
95e4b2ef RS |
2455 | (indent-according-to-mode)) |
2456 | ||
7492acc9 MM |
2457 | (defun sql-help-list-products (indent freep) |
2458 | "Generate listing of products available for use under SQLi. | |
2459 | ||
2460 | List products with :free-softare attribute set to FREEP. Indent | |
2461 | each line with INDENT." | |
2462 | ||
2463 | (let (sqli-func doc) | |
2464 | (setq doc "") | |
2465 | (dolist (p sql-product-alist) | |
2466 | (setq sqli-func (intern (concat "sql-" (symbol-name (car p))))) | |
2467 | ||
2468 | (if (and (fboundp sqli-func) | |
2469 | (eq (sql-get-product-feature (car p) :free-software) freep)) | |
2470 | (setq doc | |
2471 | (concat doc | |
2472 | indent | |
2473 | (or (sql-get-product-feature (car p) :name) | |
2474 | (symbol-name (car p))) | |
2475 | ":\t" | |
2476 | "\\[" | |
2477 | (symbol-name sqli-func) | |
2478 | "]\n")))) | |
2479 | doc)) | |
2480 | ||
95e4b2ef RS |
2481 | ;;;###autoload |
2482 | (defun sql-help () | |
801d1cb0 | 2483 | "Show short help for the SQL modes. |
95e4b2ef RS |
2484 | |
2485 | Use an entry function to open an interactive SQL buffer. This buffer is | |
dab100d7 | 2486 | usually named `*SQL*'. The name of the major mode is SQLi. |
95e4b2ef RS |
2487 | |
2488 | Use the following commands to start a specific SQL interpreter: | |
2489 | ||
7492acc9 | 2490 | \\\\FREE |
50842164 RS |
2491 | |
2492 | Other non-free SQL implementations are also supported: | |
2493 | ||
7492acc9 | 2494 | \\\\NONFREE |
50842164 RS |
2495 | |
2496 | But we urge you to choose a free implementation instead of these. | |
95e4b2ef | 2497 | |
7492acc9 MM |
2498 | You can also use \\[sql-product-interactive] to invoke the |
2499 | interpreter for the current `sql-product'. | |
2500 | ||
95e4b2ef RS |
2501 | Once you have the SQLi buffer, you can enter SQL statements in the |
2502 | buffer. The output generated is appended to the buffer and a new prompt | |
2503 | is generated. See the In/Out menu in the SQLi buffer for some functions | |
2504 | that help you navigate through the buffer, the input history, etc. | |
2505 | ||
95e4b2ef RS |
2506 | If you have a really complex SQL statement or if you are writing a |
2507 | procedure, you can do this in a separate buffer. Put the new buffer in | |
2508 | `sql-mode' by calling \\[sql-mode]. The name of this buffer can be | |
2509 | anything. The name of the major mode is SQL. | |
2510 | ||
2511 | In this SQL buffer (SQL mode), you can send the region or the entire | |
2512 | buffer to the interactive SQL buffer (SQLi mode). The results are | |
2513 | appended to the SQLi buffer without disturbing your SQL buffer." | |
2514 | (interactive) | |
7492acc9 MM |
2515 | |
2516 | ;; Insert references to loaded products into the help buffer string | |
2517 | (let ((doc (documentation 'sql-help t)) | |
2518 | changedp) | |
2519 | (setq changedp nil) | |
2520 | ||
2521 | ;; Insert FREE software list | |
2522 | (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]FREE\\s-*\n" doc 0) | |
2523 | (setq doc (replace-match (sql-help-list-products (match-string 1 doc) t) | |
2524 | t t doc 0) | |
2525 | changedp t)) | |
2526 | ||
2527 | ;; Insert non-FREE software list | |
2528 | (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]NONFREE\\s-*\n" doc 0) | |
2529 | (setq doc (replace-match (sql-help-list-products (match-string 1 doc) nil) | |
2530 | t t doc 0) | |
2531 | changedp t)) | |
2532 | ||
2533 | ;; If we changed the help text, save the change so that the help | |
2534 | ;; sub-system will see it | |
2535 | (when changedp | |
2536 | (put 'sql-help 'function-documentation doc))) | |
2537 | ||
2538 | ;; Call help on this function | |
95e4b2ef RS |
2539 | (describe-function 'sql-help)) |
2540 | ||
2541 | (defun sql-read-passwd (prompt &optional default) | |
8d68e9b5 RS |
2542 | "Read a password using PROMPT. Optional DEFAULT is password to start with." |
2543 | (read-passwd prompt nil default)) | |
95e4b2ef | 2544 | |
74790210 | 2545 | (defun sql-get-login-ext (prompt last-value history-var plist) |
5474c40f MM |
2546 | "Prompt user with extended login parameters. |
2547 | ||
74790210 | 2548 | If PLIST is nil, then the user is simply prompted for a string |
5474c40f MM |
2549 | value. |
2550 | ||
74790210 MM |
2551 | The property `:default' specifies the default value. If the |
2552 | `:number' property is non-nil then ask for a number. | |
5474c40f | 2553 | |
74790210 MM |
2554 | The `:file' property prompts for a file name that must match the |
2555 | regexp pattern specified in its value. | |
5474c40f | 2556 | |
74790210 MM |
2557 | The `:completion' property prompts for a string specified by its |
2558 | value. (The property value is used as the PREDICATE argument to | |
2559 | `completing-read'.)" | |
2560 | (let* ((default (plist-get plist :default)) | |
2561 | (prompt-def | |
2562 | (if default | |
2563 | (if (string-match "\\(\\):[ \t]*\\'" prompt) | |
2564 | (replace-match (format " (default \"%s\")" default) t t prompt 1) | |
2565 | (replace-regexp-in-string "[ \t]*\\'" | |
2566 | (format " (default \"%s\") " default) | |
2567 | prompt t t)) | |
2568 | prompt)) | |
2569 | (use-dialog-box nil)) | |
2570 | (cond | |
2571 | ((plist-member plist :file) | |
5474c40f MM |
2572 | (expand-file-name |
2573 | (read-file-name prompt | |
74790210 | 2574 | (file-name-directory last-value) default t |
5474c40f | 2575 | (file-name-nondirectory last-value) |
74790210 MM |
2576 | (when (plist-get plist :file) |
2577 | `(lambda (f) | |
2578 | (string-match | |
2579 | (concat "\\<" ,(plist-get plist :file) "\\>") | |
2580 | (file-name-nondirectory f))))))) | |
2581 | ||
2582 | ((plist-member plist :completion) | |
2583 | (completing-read prompt-def (plist-get plist :completion) nil t | |
2584 | last-value history-var default)) | |
2585 | ||
2586 | ((plist-get plist :number) | |
2587 | (read-number prompt (or default last-value 0))) | |
5474c40f | 2588 | |
74790210 MM |
2589 | (t |
2590 | (let ((r (read-from-minibuffer prompt-def last-value nil nil history-var nil))) | |
2591 | (if (string= "" r) (or default "") r)))))) | |
5474c40f | 2592 | |
95e4b2ef RS |
2593 | (defun sql-get-login (&rest what) |
2594 | "Get username, password and database from the user. | |
2595 | ||
dab100d7 | 2596 | The variables `sql-user', `sql-password', `sql-server', and |
eb3f61dd | 2597 | `sql-database' can be customized. They are used as the default values. |
dab100d7 RS |
2598 | Usernames, servers and databases are stored in `sql-user-history', |
2599 | `sql-server-history' and `database-history'. Passwords are not stored | |
2600 | in a history. | |
95e4b2ef | 2601 | |
7492acc9 MM |
2602 | Parameter WHAT is a list of tokens passed as arguments in the |
2603 | function call. The function asks for the username if WHAT | |
2604 | contains the symbol `user', for the password if it contains the | |
2605 | symbol `password', for the server if it contains the symbol | |
2606 | `server', and for the database if it contains the symbol | |
2607 | `database'. The members of WHAT are processed in the order in | |
2608 | which they are provided. | |
95e4b2ef | 2609 | |
74790210 MM |
2610 | Each token may also be a list with the token in the car and a |
2611 | plist of options as the cdr. The following properties are | |
2612 | supported: | |
5474c40f | 2613 | |
74790210 MM |
2614 | :file <filename-regexp> |
2615 | :completion <list-of-strings-or-function> | |
2616 | :default <default-value> | |
2617 | :number t | |
5474c40f | 2618 | |
95e4b2ef RS |
2619 | In order to ask the user for username, password and database, call the |
2620 | function like this: (sql-get-login 'user 'password 'database)." | |
2621 | (interactive) | |
74790210 MM |
2622 | (mapcar |
2623 | (lambda (w) | |
2624 | (let ((token (or (and (consp w) (car w)) w)) | |
2625 | (plist (or (and (consp w) (cdr w)) nil))) | |
2626 | ||
2627 | (cond | |
2628 | ((eq token 'user) ; user | |
2629 | (setq sql-user | |
2630 | (sql-get-login-ext "User: " sql-user | |
2631 | 'sql-user-history plist))) | |
2632 | ||
2633 | ((eq token 'password) ; password | |
2634 | (setq sql-password | |
2635 | (sql-read-passwd "Password: " sql-password))) | |
2636 | ||
2637 | ((eq token 'server) ; server | |
2638 | (setq sql-server | |
2639 | (sql-get-login-ext "Server: " sql-server | |
2640 | 'sql-server-history plist))) | |
2641 | ||
2642 | ((eq token 'database) ; database | |
2643 | (setq sql-database | |
2644 | (sql-get-login-ext "Database: " sql-database | |
2645 | 'sql-database-history plist))) | |
2646 | ||
2647 | ((eq token 'port) ; port | |
2648 | (setq sql-port | |
2649 | (sql-get-login-ext "Port: " sql-port | |
2650 | nil (append '(:number t) plist))))))) | |
2651 | what)) | |
2652 | ||
2653 | (defun sql-find-sqli-buffer (&optional product) | |
9250002f MM |
2654 | "Returns the name of the current default SQLi buffer or nil. |
2655 | In order to qualify, the SQLi buffer must be alive, be in | |
2656 | `sql-interactive-mode' and have a process." | |
a386ac70 | 2657 | (let ((buf sql-buffer) |
74790210 | 2658 | (prod (or product sql-product))) |
a386ac70 MM |
2659 | (or |
2660 | ;; Current sql-buffer, if there is one. | |
2661 | (and (sql-buffer-live-p buf prod) | |
2662 | buf) | |
2663 | ;; Global sql-buffer | |
2664 | (and (setq buf (default-value 'sql-buffer)) | |
2665 | (sql-buffer-live-p buf prod) | |
2666 | buf) | |
2667 | ;; Look thru each buffer | |
2668 | (car (apply 'append | |
2669 | (mapcar (lambda (b) | |
2670 | (and (sql-buffer-live-p b prod) | |
2671 | (list (buffer-name b)))) | |
2672 | (buffer-list))))))) | |
46d94d0d GM |
2673 | |
2674 | (defun sql-set-sqli-buffer-generally () | |
f4df536d | 2675 | "Set SQLi buffer for all SQL buffers that have none. |
46d94d0d GM |
2676 | This function checks all SQL buffers for their SQLi buffer. If their |
2677 | SQLi buffer is nonexistent or has no process, it is set to the current | |
2678 | default SQLi buffer. The current default SQLi buffer is determined | |
2679 | using `sql-find-sqli-buffer'. If `sql-buffer' is set, | |
2680 | `sql-set-sqli-hook' is run." | |
2681 | (interactive) | |
2682 | (save-excursion | |
2683 | (let ((buflist (buffer-list)) | |
9250002f MM |
2684 | (default-buffer (sql-find-sqli-buffer))) |
2685 | (setq-default sql-buffer default-buffer) | |
46d94d0d GM |
2686 | (while (not (null buflist)) |
2687 | (let ((candidate (car buflist))) | |
2688 | (set-buffer candidate) | |
55659495 | 2689 | (if (and (derived-mode-p 'sql-mode) |
a386ac70 | 2690 | (not (sql-buffer-live-p sql-buffer))) |
46d94d0d | 2691 | (progn |
9250002f | 2692 | (setq sql-buffer default-buffer) |
a386ac70 MM |
2693 | (when default-buffer |
2694 | (run-hooks 'sql-set-sqli-hook))))) | |
46d94d0d GM |
2695 | (setq buflist (cdr buflist)))))) |
2696 | ||
c7055d66 RS |
2697 | (defun sql-set-sqli-buffer () |
2698 | "Set the SQLi buffer SQL strings are sent to. | |
95e4b2ef | 2699 | |
c7055d66 RS |
2700 | Call this function in a SQL buffer in order to set the SQLi buffer SQL |
2701 | strings are sent to. Calling this function sets `sql-buffer' and runs | |
2702 | `sql-set-sqli-hook'. | |
dab100d7 | 2703 | |
c7055d66 | 2704 | If you call it from a SQL buffer, this sets the local copy of |
801d1cb0 | 2705 | `sql-buffer'. |
dab100d7 | 2706 | |
c7055d66 | 2707 | If you call it from anywhere else, it sets the global copy of |
dab100d7 RS |
2708 | `sql-buffer'." |
2709 | (interactive) | |
46d94d0d GM |
2710 | (let ((default-buffer (sql-find-sqli-buffer))) |
2711 | (if (null default-buffer) | |
a386ac70 MM |
2712 | (error "There is no suitable SQLi buffer") |
2713 | (let ((new-buffer (read-buffer "New SQLi buffer: " default-buffer t))) | |
2714 | (if (null (sql-buffer-live-p new-buffer)) | |
2715 | (error "Buffer %s is not a working SQLi buffer" new-buffer) | |
2716 | (when new-buffer | |
2717 | (setq sql-buffer new-buffer) | |
2718 | (run-hooks 'sql-set-sqli-hook))))))) | |
dab100d7 RS |
2719 | |
2720 | (defun sql-show-sqli-buffer () | |
2721 | "Show the name of current SQLi buffer. | |
2722 | ||
2723 | This is the buffer SQL strings are sent to. It is stored in the | |
2724 | variable `sql-buffer'. See `sql-help' on how to create such a buffer." | |
2725 | (interactive) | |
9250002f | 2726 | (if (null (buffer-live-p (get-buffer sql-buffer))) |
c7055d66 | 2727 | (message "%s has no SQLi buffer set." (buffer-name (current-buffer))) |
dab100d7 | 2728 | (if (null (get-buffer-process sql-buffer)) |
9250002f MM |
2729 | (message "Buffer %s has no process." sql-buffer) |
2730 | (message "Current SQLi buffer is %s." sql-buffer)))) | |
dab100d7 | 2731 | |
c7055d66 | 2732 | (defun sql-make-alternate-buffer-name () |
c38762fd | 2733 | "Return a string that can be used to rename a SQLi buffer. |
c7055d66 RS |
2734 | |
2735 | This is used to set `sql-alternate-buffer-name' within | |
30c4d8dc MM |
2736 | `sql-interactive-mode'. |
2737 | ||
2738 | If the session was started with `sql-connect' then the alternate | |
2739 | name would be the name of the connection. | |
2740 | ||
2741 | Otherwise, it uses the parameters identified by the :sqlilogin | |
2742 | parameter. | |
2743 | ||
2744 | If all else fails, the alternate name would be the user and | |
2745 | server/database name." | |
2746 | ||
d26b0ea9 MM |
2747 | (let ((name "")) |
2748 | ||
5474c40f MM |
2749 | ;; Build a name using the :sqli-login setting |
2750 | (setq name | |
2751 | (apply 'concat | |
3bd2cfef MM |
2752 | (cdr |
2753 | (apply 'append nil | |
2754 | (sql-for-each-login | |
2755 | (sql-get-product-feature sql-product :sqli-login) | |
74790210 | 2756 | (lambda (token plist) |
3bd2cfef MM |
2757 | (cond |
2758 | ((eq token 'user) | |
2759 | (unless (string= "" sql-user) | |
2760 | (list "/" sql-user))) | |
2761 | ((eq token 'port) | |
9250002f MM |
2762 | (unless (or (not (numberp sql-port)) |
2763 | (= 0 sql-port)) | |
2764 | (list ":" (number-to-string sql-port)))) | |
3bd2cfef MM |
2765 | ((eq token 'server) |
2766 | (unless (string= "" sql-server) | |
2767 | (list "." | |
74790210 | 2768 | (if (plist-member plist :file) |
3bd2cfef MM |
2769 | (file-name-nondirectory sql-server) |
2770 | sql-server)))) | |
2771 | ((eq token 'database) | |
9250002f | 2772 | (unless (string= "" sql-database) |
3bd2cfef | 2773 | (list "@" |
74790210 | 2774 | (if (plist-member plist :file) |
3bd2cfef MM |
2775 | (file-name-nondirectory sql-database) |
2776 | sql-database)))) | |
2777 | ||
2778 | ((eq token 'password) nil) | |
2779 | (t nil)))))))) | |
5474c40f MM |
2780 | |
2781 | ;; If there's a connection, use it and the name thus far | |
d26b0ea9 MM |
2782 | (if sql-connection |
2783 | (format "<%s>%s" sql-connection (or name "")) | |
5474c40f MM |
2784 | |
2785 | ;; If there is no name, try to create something meaningful | |
2786 | (if (string= "" (or name "")) | |
2787 | (concat | |
2788 | (if (string= "" sql-user) | |
2789 | (if (string= "" (user-login-name)) | |
2790 | () | |
2791 | (concat (user-login-name) "/")) | |
2792 | (concat sql-user "/")) | |
2793 | (if (string= "" sql-database) | |
2794 | (if (string= "" sql-server) | |
2795 | (system-name) | |
2796 | sql-server) | |
2797 | sql-database)) | |
2798 | ||
3bd2cfef MM |
2799 | ;; Use the name we've got |
2800 | name)))) | |
c7055d66 | 2801 | |
9250002f MM |
2802 | (defun sql-rename-buffer (&optional new-name) |
2803 | "Rename a SQL interactive buffer. | |
2804 | ||
2805 | Prompts for the new name if command is preceeded by | |
2806 | \\[universal-argument]. If no buffer name is provided, then the | |
2807 | `sql-alternate-buffer-name' is used. | |
2808 | ||
2809 | The actual buffer name set will be \"*SQL: NEW-NAME*\". If | |
2810 | NEW-NAME is empty, then the buffer name will be \"*SQL*\"." | |
2811 | (interactive "P") | |
2812 | ||
2813 | (if (not (derived-mode-p 'sql-interactive-mode)) | |
2814 | (message "Current buffer is not a SQL interactive buffer") | |
2815 | ||
a386ac70 MM |
2816 | (setq sql-alternate-buffer-name |
2817 | (cond | |
2818 | ((stringp new-name) new-name) | |
2819 | ((consp new-name) | |
9250002f | 2820 | (read-string "Buffer name (\"*SQL: XXX*\"; enter `XXX'): " |
a386ac70 MM |
2821 | sql-alternate-buffer-name)) |
2822 | (t sql-alternate-buffer-name))) | |
9250002f MM |
2823 | |
2824 | (rename-buffer (if (string= "" sql-alternate-buffer-name) | |
2825 | "*SQL*" | |
2826 | (format "*SQL: %s*" sql-alternate-buffer-name)) | |
2827 | t))) | |
c7055d66 | 2828 | |
95e4b2ef RS |
2829 | (defun sql-copy-column () |
2830 | "Copy current column to the end of buffer. | |
2831 | Inserts SELECT or commas if appropriate." | |
2832 | (interactive) | |
2833 | (let ((column)) | |
2834 | (save-excursion | |
7492acc9 | 2835 | (setq column (buffer-substring-no-properties |
95e4b2ef RS |
2836 | (progn (forward-char 1) (backward-sexp 1) (point)) |
2837 | (progn (forward-sexp 1) (point)))) | |
2838 | (goto-char (point-max)) | |
3035b156 MB |
2839 | (let ((bol (comint-line-beginning-position))) |
2840 | (cond | |
2841 | ;; if empty command line, insert SELECT | |
2842 | ((= bol (point)) | |
2843 | (insert "SELECT ")) | |
2844 | ;; else if appending to INTO .* (, SELECT or ORDER BY, insert a comma | |
2845 | ((save-excursion | |
2846 | (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+" | |
2847 | bol t)) | |
2848 | (insert ", ")) | |
2849 | ;; else insert a space | |
2850 | (t | |
b9584f65 | 2851 | (if (eq (preceding-char) ?\s) |
3035b156 MB |
2852 | nil |
2853 | (insert " "))))) | |
95e4b2ef RS |
2854 | ;; in any case, insert the column |
2855 | (insert column) | |
2856 | (message "%s" column)))) | |
2857 | ||
063c6324 JB |
2858 | ;; On Windows, SQL*Plus for Oracle turns on full buffering for stdout |
2859 | ;; if it is not attached to a character device; therefore placeholder | |
77d352a6 GM |
2860 | ;; replacement by SQL*Plus is fully buffered. The workaround lets |
2861 | ;; Emacs query for the placeholders. | |
2862 | ||
2863 | (defvar sql-placeholder-history nil | |
2864 | "History of placeholder values used.") | |
2865 | ||
7492acc9 MM |
2866 | (defun sql-placeholders-filter (string) |
2867 | "Replace placeholders in STRING. | |
c38762fd | 2868 | Placeholders are words starting with an ampersand like &this." |
7492acc9 MM |
2869 | |
2870 | (when sql-oracle-scan-on | |
2871 | (while (string-match "&\\(\\sw+\\)" string) | |
2872 | (setq string (replace-match | |
2873 | (read-from-minibuffer | |
2874 | (format "Enter value for %s: " (match-string 1 string)) | |
2875 | nil nil nil 'sql-placeholder-history) | |
2876 | t t string)))) | |
2877 | string) | |
77d352a6 | 2878 | |
624ef9b3 GM |
2879 | ;; Using DB2 interactively, newlines must be escaped with " \". |
2880 | ;; The space before the backslash is relevant. | |
7492acc9 | 2881 | (defun sql-escape-newlines-filter (string) |
c38762fd | 2882 | "Escape newlines in STRING. |
624ef9b3 GM |
2883 | Every newline in STRING will be preceded with a space and a backslash." |
2884 | (let ((result "") (start 0) mb me) | |
2885 | (while (string-match "\n" string start) | |
2886 | (setq mb (match-beginning 0) | |
7492acc9 MM |
2887 | me (match-end 0) |
2888 | result (concat result | |
2889 | (substring string start mb) | |
2890 | (if (and (> mb 1) | |
2891 | (string-equal " \\" (substring string (- mb 2) mb))) | |
2892 | "" " \\\n")) | |
2893 | start me)) | |
2894 | (concat result (substring string start)))) | |
624ef9b3 | 2895 | |
95e4b2ef RS |
2896 | \f |
2897 | ||
7492acc9 MM |
2898 | ;;; Input sender for SQLi buffers |
2899 | ||
3bd2cfef MM |
2900 | (defvar sql-output-newline-count 0 |
2901 | "Number of newlines in the input string. | |
2902 | ||
2903 | Allows the suppression of continuation prompts.") | |
2904 | ||
2905 | (defvar sql-output-by-send nil | |
2906 | "Non-nil if the command in the input was generated by `sql-send-string'.") | |
2907 | ||
7492acc9 | 2908 | (defun sql-input-sender (proc string) |
c38762fd | 2909 | "Send STRING to PROC after applying filters." |
7492acc9 MM |
2910 | |
2911 | (let* ((product (with-current-buffer (process-buffer proc) sql-product)) | |
2912 | (filter (sql-get-product-feature product :input-filter))) | |
2913 | ||
3bd2cfef MM |
2914 | ;; Apply filter(s) |
2915 | (cond | |
2916 | ((not filter) | |
2917 | nil) | |
2918 | ((functionp filter) | |
2919 | (setq string (funcall filter string))) | |
2920 | ((listp filter) | |
2921 | (mapc (lambda (f) (setq string (funcall f string))) filter)) | |
2922 | (t nil)) | |
2923 | ||
2924 | ;; Count how many newlines in the string | |
2925 | (setq sql-output-newline-count 0) | |
2926 | (mapc (lambda (ch) | |
2927 | (when (eq ch ?\n) | |
2928 | (setq sql-output-newline-count (1+ sql-output-newline-count)))) | |
2929 | string) | |
2930 | ||
7492acc9 | 2931 | ;; Send the string |
3bd2cfef MM |
2932 | (comint-simple-send proc string))) |
2933 | ||
2934 | ;;; Strip out continuation prompts | |
2935 | ||
2936 | (defun sql-interactive-remove-continuation-prompt (oline) | |
2937 | "Strip out continuation prompts out of the OLINE. | |
2938 | ||
2939 | Added to the `comint-preoutput-filter-functions' hook in a SQL | |
2940 | interactive buffer. If `sql-outut-newline-count' is greater than | |
2941 | zero, then an output line matching the continuation prompt is filtered | |
2942 | out. If the count is one, then the prompt is replaced with a newline | |
2943 | to force the output from the query to appear on a new line." | |
2944 | (if (and sql-prompt-cont-regexp | |
2945 | sql-output-newline-count | |
2946 | (numberp sql-output-newline-count) | |
2947 | (>= sql-output-newline-count 1)) | |
2948 | (progn | |
2949 | (while (and oline | |
2950 | sql-output-newline-count | |
2951 | (> sql-output-newline-count 0) | |
2952 | (string-match sql-prompt-cont-regexp oline)) | |
2953 | ||
2954 | (setq oline | |
2955 | (replace-match (if (and | |
2956 | (= 1 sql-output-newline-count) | |
2957 | sql-output-by-send) | |
2958 | "\n" "") | |
2959 | nil nil oline) | |
2960 | sql-output-newline-count | |
2961 | (1- sql-output-newline-count))) | |
2962 | (if (= sql-output-newline-count 0) | |
2963 | (setq sql-output-newline-count nil)) | |
2964 | (setq sql-output-by-send nil)) | |
2965 | (setq sql-output-newline-count nil)) | |
2966 | oline) | |
7492acc9 | 2967 | |
95e4b2ef RS |
2968 | ;;; Sending the region to the SQLi buffer. |
2969 | ||
7492acc9 MM |
2970 | (defun sql-send-string (str) |
2971 | "Send the string STR to the SQL process." | |
2972 | (interactive "sSQL Text: ") | |
2973 | ||
3bd2cfef MM |
2974 | (let ((comint-input-sender-no-newline nil) |
2975 | (s (replace-regexp-in-string "[[:space:]\n\r]+\\'" "" str))) | |
9250002f | 2976 | (if (sql-buffer-live-p sql-buffer) |
7492acc9 MM |
2977 | (progn |
2978 | ;; Ignore the hoping around... | |
2979 | (save-excursion | |
7492acc9 MM |
2980 | ;; Set product context |
2981 | (with-current-buffer sql-buffer | |
3bd2cfef MM |
2982 | ;; Send the string (trim the trailing whitespace) |
2983 | (sql-input-sender (get-buffer-process sql-buffer) s) | |
7492acc9 MM |
2984 | |
2985 | ;; Send a command terminator if we must | |
2986 | (if sql-send-terminator | |
3bd2cfef | 2987 | (sql-send-magic-terminator sql-buffer s sql-send-terminator)) |
7492acc9 | 2988 | |
9250002f | 2989 | (message "Sent string to buffer %s." sql-buffer))) |
7492acc9 MM |
2990 | |
2991 | ;; Display the sql buffer | |
2992 | (if sql-pop-to-buffer-after-send-region | |
2993 | (pop-to-buffer sql-buffer) | |
2994 | (display-buffer sql-buffer))) | |
2995 | ||
2996 | ;; We don't have no stinkin' sql | |
2997 | (message "No SQL process started.")))) | |
2998 | ||
95e4b2ef RS |
2999 | (defun sql-send-region (start end) |
3000 | "Send a region to the SQL process." | |
3001 | (interactive "r") | |
7492acc9 | 3002 | (sql-send-string (buffer-substring-no-properties start end))) |
95e4b2ef | 3003 | |
dab100d7 RS |
3004 | (defun sql-send-paragraph () |
3005 | "Send the current paragraph to the SQL process." | |
3006 | (interactive) | |
3007 | (let ((start (save-excursion | |
3008 | (backward-paragraph) | |
3009 | (point))) | |
3010 | (end (save-excursion | |
3011 | (forward-paragraph) | |
3012 | (point)))) | |
3013 | (sql-send-region start end))) | |
3014 | ||
95e4b2ef RS |
3015 | (defun sql-send-buffer () |
3016 | "Send the buffer contents to the SQL process." | |
3017 | (interactive) | |
3018 | (sql-send-region (point-min) (point-max))) | |
3019 | ||
7492acc9 | 3020 | (defun sql-send-magic-terminator (buf str terminator) |
c38762fd | 3021 | "Send TERMINATOR to buffer BUF if its not present in STR." |
3bd2cfef | 3022 | (let (comint-input-sender-no-newline pat term) |
7492acc9 MM |
3023 | ;; If flag is merely on(t), get product-specific terminator |
3024 | (if (eq terminator t) | |
3025 | (setq terminator (sql-get-product-feature sql-product :terminator))) | |
3026 | ||
3027 | ;; If there is no terminator specified, use default ";" | |
3028 | (unless terminator | |
3029 | (setq terminator ";")) | |
3030 | ||
3031 | ;; Parse the setting into the pattern and the terminator string | |
3032 | (cond ((stringp terminator) | |
3033 | (setq pat (regexp-quote terminator) | |
3034 | term terminator)) | |
3035 | ((consp terminator) | |
3036 | (setq pat (car terminator) | |
3037 | term (cdr terminator))) | |
3038 | (t | |
3039 | nil)) | |
3040 | ||
3041 | ;; Check to see if the pattern is present in the str already sent | |
3042 | (unless (and pat term | |
3bd2cfef MM |
3043 | (string-match (concat pat "\\'") str)) |
3044 | (comint-simple-send (get-buffer-process buf) term) | |
3045 | (setq sql-output-newline-count | |
3046 | (if sql-output-newline-count | |
3047 | (1+ sql-output-newline-count) | |
3048 | 1))) | |
3049 | (setq sql-output-by-send t))) | |
7492acc9 MM |
3050 | |
3051 | (defun sql-remove-tabs-filter (str) | |
3052 | "Replace tab characters with spaces." | |
3053 | (replace-regexp-in-string "\t" " " str nil t)) | |
9fd8cb36 | 3054 | |
95e4b2ef RS |
3055 | (defun sql-toggle-pop-to-buffer-after-send-region (&optional value) |
3056 | "Toggle `sql-pop-to-buffer-after-send-region'. | |
3057 | ||
3058 | If given the optional parameter VALUE, sets | |
063c6324 | 3059 | `sql-toggle-pop-to-buffer-after-send-region' to VALUE." |
95e4b2ef RS |
3060 | (interactive "P") |
3061 | (if value | |
3062 | (setq sql-pop-to-buffer-after-send-region value) | |
801d1cb0 | 3063 | (setq sql-pop-to-buffer-after-send-region |
7492acc9 | 3064 | (null sql-pop-to-buffer-after-send-region)))) |
95e4b2ef RS |
3065 | |
3066 | \f | |
3067 | ||
a386ac70 MM |
3068 | ;;; Redirect output functions |
3069 | ||
3070 | (defun sql-redirect (command combuf &optional outbuf save-prior) | |
3071 | "Execute the SQL command and send output to OUTBUF. | |
3072 | ||
3073 | COMBUF must be an active SQL interactive buffer. OUTBUF may be | |
3074 | an existing buffer, or the name of a non-existing buffer. If | |
3075 | omitted the output is sent to a temporary buffer which will be | |
3076 | killed after the command completes. COMMAND should be a string | |
3077 | of commands accepted by the SQLi program." | |
3078 | ||
3079 | (with-current-buffer combuf | |
3080 | (let ((buf (get-buffer-create (or outbuf " *SQL-Redirect*"))) | |
3081 | (proc (get-buffer-process (current-buffer))) | |
3082 | (comint-prompt-regexp (sql-get-product-feature sql-product | |
3083 | :prompt-regexp)) | |
3084 | (start nil)) | |
3085 | (with-current-buffer buf | |
74790210 | 3086 | (toggle-read-only -1) |
a386ac70 MM |
3087 | (unless save-prior |
3088 | (erase-buffer)) | |
3089 | (goto-char (point-max)) | |
74790210 MM |
3090 | (unless (zerop (buffer-size)) |
3091 | (insert "\n")) | |
a386ac70 MM |
3092 | (setq start (point))) |
3093 | ||
3094 | ;; Run the command | |
74790210 | 3095 | (message "Executing SQL command...") |
a386ac70 MM |
3096 | (comint-redirect-send-command-to-process command buf proc nil t) |
3097 | (while (null comint-redirect-completed) | |
3098 | (accept-process-output nil 1)) | |
74790210 | 3099 | (message "Executing SQL command...done") |
a386ac70 | 3100 | |
74790210 | 3101 | ;; Clean up the output results |
a386ac70 | 3102 | (with-current-buffer buf |
74790210 MM |
3103 | ;; Remove trailing whitespace |
3104 | (goto-char (point-max)) | |
3105 | (when (looking-back "[ \t\f\n\r]*" start) | |
3106 | (delete-region (match-beginning 0) (match-end 0))) | |
3107 | ;; Remove echo if there was one | |
a386ac70 MM |
3108 | (goto-char start) |
3109 | (when (looking-at (concat "^" (regexp-quote command) "[\\n]")) | |
3110 | (delete-region (match-beginning 0) (match-end 0))) | |
3111 | (goto-char start))))) | |
3112 | ||
3113 | (defun sql-redirect-value (command combuf regexp &optional regexp-groups) | |
3114 | "Execute the SQL command and return part of result. | |
3115 | ||
3116 | COMBUF must be an active SQL interactive buffer. COMMAND should | |
3117 | be a string of commands accepted by the SQLi program. From the | |
3118 | output, the REGEXP is repeatedly matched and the list of | |
3119 | REGEXP-GROUPS submatches is returned. This behaves much like | |
3120 | \\[comint-redirect-results-list-from-process] but instead of | |
3121 | returning a single submatch it returns a list of each submatch | |
3122 | for each match." | |
3123 | ||
3124 | (let ((outbuf " *SQL-Redirect-values*") | |
3125 | (results nil)) | |
3126 | (sql-redirect command combuf outbuf nil) | |
3127 | (with-current-buffer outbuf | |
3128 | (while (re-search-forward regexp nil t) | |
3129 | (push | |
3130 | (cond | |
3131 | ;; no groups-return all of them | |
3132 | ((null regexp-groups) | |
3133 | (let ((i 1) | |
3134 | (r nil)) | |
3135 | (while (match-beginning i) | |
3136 | (push (match-string i) r)) | |
3137 | (nreverse r))) | |
3138 | ;; one group specified | |
3139 | ((numberp regexp-groups) | |
3140 | (match-string regexp-groups)) | |
a386ac70 MM |
3141 | ;; list of numbers; return the specified matches only |
3142 | ((consp regexp-groups) | |
3143 | (mapcar (lambda (c) | |
3144 | (cond | |
3145 | ((numberp c) (match-string c)) | |
3146 | ((stringp c) (match-substitute-replacement c)) | |
3147 | (t (error "sql-redirect-value: unknown REGEXP-GROUPS value - %s" c)))) | |
3148 | regexp-groups)) | |
3149 | ;; String is specified; return replacement string | |
3150 | ((stringp regexp-groups) | |
3151 | (match-substitute-replacement regexp-groups)) | |
3152 | (t | |
3153 | (error "sql-redirect-value: unknown REGEXP-GROUPS value - %s" | |
3154 | regexp-groups))) | |
3155 | results))) | |
3156 | (nreverse results))) | |
3157 | ||
74790210 MM |
3158 | (defun sql-execute (sqlbuf outbuf command arg) |
3159 | "Executes a command in a SQL interacive buffer and captures the output. | |
3160 | ||
3161 | The commands are run in SQLBUF and the output saved in OUTBUF. | |
3162 | COMMAND must be a string, a function or a list of such elements. | |
3163 | Functions are called with SQLBUF, OUTBUF and ARG as parameters; | |
3164 | strings are formatted with ARG and executed. | |
3165 | ||
3166 | If the results are empty the OUTBUF is deleted, otherwise the | |
3167 | buffer is popped into a view window. " | |
3168 | (mapc | |
3169 | (lambda (c) | |
3170 | (cond | |
3171 | ((stringp c) | |
3172 | (sql-redirect (if arg (format c arg) c) sqlbuf outbuf) t) | |
3173 | ((functionp c) | |
3174 | (apply c sqlbuf outbuf arg)) | |
3175 | (t (error "Unknown sql-execute item %s" c)))) | |
3176 | (if (consp command) command (cons command nil))) | |
3177 | ||
3178 | (setq outbuf (get-buffer outbuf)) | |
3179 | (if (zerop (buffer-size outbuf)) | |
3180 | (kill-buffer outbuf) | |
3181 | (let ((one-win (eq (selected-window) | |
3182 | (get-lru-window)))) | |
3183 | (with-current-buffer outbuf | |
3184 | (set-buffer-modified-p nil) | |
3185 | (toggle-read-only 1)) | |
3186 | (view-buffer-other-window outbuf) | |
3187 | (when one-win | |
3188 | (shrink-window-if-larger-than-buffer))))) | |
3189 | ||
3190 | (defun sql-execute-feature (sqlbuf outbuf feature enhanced arg) | |
3191 | "List objects or details in a separate display buffer." | |
3192 | (let (command) | |
3193 | (with-current-buffer sqlbuf | |
3194 | (setq command (sql-get-product-feature sql-product feature))) | |
3195 | (unless command | |
3196 | (error "%s does not support %s" sql-product feature)) | |
3197 | (when (consp command) | |
3198 | (setq command (if enhanced | |
3199 | (cdr command) | |
3200 | (car command)))) | |
3201 | (sql-execute sqlbuf outbuf command arg))) | |
3202 | ||
3203 | (defun sql-read-table-name (prompt) | |
3204 | "Read the name of a database table." | |
3205 | ;; TODO: Fetch table/view names from database and provide completion. | |
3206 | ;; Also implement thing-at-point if the buffer has valid names in it | |
3207 | ;; (i.e. sql-mode, sql-interactive-mode, or sql-list-all buffers) | |
3208 | (read-from-minibuffer prompt)) | |
3209 | ||
3210 | (defun sql-list-all (&optional enhanced) | |
3211 | "List all database objects." | |
3212 | (interactive "P") | |
3213 | (let ((sqlbuf (sql-find-sqli-buffer))) | |
3214 | (unless sqlbuf | |
3215 | (error "No SQL interactive buffer found")) | |
3216 | (sql-execute-feature sqlbuf "*List All*" :list-all enhanced nil))) | |
3217 | ||
3218 | (defun sql-list-table (name &optional enhanced) | |
3219 | "List the details of a database table. " | |
3220 | (interactive | |
3221 | (list (sql-read-table-name "Table name: ") | |
3222 | current-prefix-arg)) | |
3223 | (let ((sqlbuf (sql-find-sqli-buffer))) | |
3224 | (unless sqlbuf | |
3225 | (error "No SQL interactive buffer found")) | |
3226 | (unless name | |
3227 | (error "No table name specified")) | |
3228 | (sql-execute-feature sqlbuf (format "*List %s*" name) | |
3229 | :list-table enhanced name))) | |
3230 | ||
a386ac70 MM |
3231 | \f |
3232 | ||
95e4b2ef RS |
3233 | ;;; SQL mode -- uses SQL interactive mode |
3234 | ||
3235 | ;;;###autoload | |
175069ef | 3236 | (define-derived-mode sql-mode prog-mode "SQL" |
95e4b2ef RS |
3237 | "Major mode to edit SQL. |
3238 | ||
dab100d7 | 3239 | You can send SQL statements to the SQLi buffer using |
95e4b2ef | 3240 | \\[sql-send-region]. Such a buffer must exist before you can do this. |
dab100d7 | 3241 | See `sql-help' on how to create SQLi buffers. |
95e4b2ef | 3242 | |
801d1cb0 | 3243 | \\{sql-mode-map} |
95e4b2ef RS |
3244 | Customization: Entry to this mode runs the `sql-mode-hook'. |
3245 | ||
dab100d7 RS |
3246 | When you put a buffer in SQL mode, the buffer stores the last SQLi |
3247 | buffer created as its destination in the variable `sql-buffer'. This | |
3248 | will be the buffer \\[sql-send-region] sends the region to. If this | |
3249 | SQLi buffer is killed, \\[sql-send-region] is no longer able to | |
c7055d66 RS |
3250 | determine where the strings should be sent to. You can set the |
3251 | value of `sql-buffer' using \\[sql-set-sqli-buffer]. | |
95e4b2ef | 3252 | |
dab100d7 | 3253 | For information on how to create multiple SQLi buffers, see |
4da8ff79 RS |
3254 | `sql-interactive-mode'. |
3255 | ||
3256 | Note that SQL doesn't have an escape character unless you specify | |
3257 | one. If you specify backslash as escape character in SQL, | |
3258 | you must tell Emacs. Here's how to do that in your `~/.emacs' file: | |
3259 | ||
3260 | \(add-hook 'sql-mode-hook | |
3261 | (lambda () | |
3262 | (modify-syntax-entry ?\\\\ \".\" sql-mode-syntax-table)))" | |
175069ef | 3263 | :abbrev-table sql-mode-abbrev-table |
311e7a89 GM |
3264 | (if sql-mode-menu |
3265 | (easy-menu-add sql-mode-menu)); XEmacs | |
175069ef SM |
3266 | |
3267 | (set (make-local-variable 'comment-start) "--") | |
801d1cb0 | 3268 | ;; Make each buffer in sql-mode remember the "current" SQLi buffer. |
dab100d7 | 3269 | (make-local-variable 'sql-buffer) |
801d1cb0 AS |
3270 | ;; Add imenu support for sql-mode. Note that imenu-generic-expression |
3271 | ;; is buffer-local, so we don't need a local-variable for it. SQL is | |
3272 | ;; case-insensitive, that's why we have to set imenu-case-fold-search. | |
801d1cb0 | 3273 | (setq imenu-generic-expression sql-imenu-generic-expression |
78024f88 | 3274 | imenu-case-fold-search t) |
c7055d66 RS |
3275 | ;; Make `sql-send-paragraph' work on paragraphs that contain indented |
3276 | ;; lines. | |
175069ef SM |
3277 | (set (make-local-variable 'paragraph-separate) "[\f]*$") |
3278 | (set (make-local-variable 'paragraph-start) "[\n\f]") | |
801d1cb0 | 3279 | ;; Abbrevs |
95e4b2ef | 3280 | (setq abbrev-all-caps 1) |
78024f88 | 3281 | ;; Catch changes to sql-product and highlight accordingly |
78024f88 | 3282 | (add-hook 'hack-local-variables-hook 'sql-highlight-product t t)) |
95e4b2ef RS |
3283 | |
3284 | \f | |
3285 | ||
3286 | ;;; SQL interactive mode | |
3287 | ||
3288 | (put 'sql-interactive-mode 'mode-class 'special) | |
3289 | ||
3290 | (defun sql-interactive-mode () | |
3291 | "Major mode to use a SQL interpreter interactively. | |
3292 | ||
3293 | Do not call this function by yourself. The environment must be | |
063c6324 JB |
3294 | initialized by an entry function specific for the SQL interpreter. |
3295 | See `sql-help' for a list of available entry functions. | |
95e4b2ef RS |
3296 | |
3297 | \\[comint-send-input] after the end of the process' output sends the | |
3298 | text from the end of process to the end of the current line. | |
3299 | \\[comint-send-input] before end of process output copies the current | |
3300 | line minus the prompt to the end of the buffer and sends it. | |
3301 | \\[comint-copy-old-input] just copies the current line. | |
3302 | Use \\[sql-accumulate-and-indent] to enter multi-line statements. | |
3303 | ||
3304 | If you want to make multiple SQL buffers, rename the `*SQL*' buffer | |
3305 | using \\[rename-buffer] or \\[rename-uniquely] and start a new process. | |
dab100d7 RS |
3306 | See `sql-help' for a list of available entry functions. The last buffer |
3307 | created by such an entry function is the current SQLi buffer. SQL | |
3308 | buffers will send strings to the SQLi buffer current at the time of | |
3309 | their creation. See `sql-mode' for details. | |
3310 | ||
3311 | Sample session using two connections: | |
3312 | ||
3313 | 1. Create first SQLi buffer by calling an entry function. | |
3314 | 2. Rename buffer \"*SQL*\" to \"*Connection 1*\". | |
3315 | 3. Create a SQL buffer \"test1.sql\". | |
3316 | 4. Create second SQLi buffer by calling an entry function. | |
3317 | 5. Rename buffer \"*SQL*\" to \"*Connection 2*\". | |
3318 | 6. Create a SQL buffer \"test2.sql\". | |
3319 | ||
3320 | Now \\[sql-send-region] in buffer \"test1.sql\" will send the region to | |
3321 | buffer \"*Connection 1*\", \\[sql-send-region] in buffer \"test2.sql\" | |
3322 | will send the region to buffer \"*Connection 2*\". | |
95e4b2ef RS |
3323 | |
3324 | If you accidentally suspend your process, use \\[comint-continue-subjob] | |
dab100d7 RS |
3325 | to continue it. On some operating systems, this will not work because |
3326 | the signals are not supported. | |
95e4b2ef RS |
3327 | |
3328 | \\{sql-interactive-mode-map} | |
3329 | Customization: Entry to this mode runs the hooks on `comint-mode-hook' | |
3330 | and `sql-interactive-mode-hook' (in that order). Before each input, the | |
3331 | hooks on `comint-input-filter-functions' are run. After each SQL | |
3332 | interpreter output, the hooks on `comint-output-filter-functions' are | |
3333 | run. | |
3334 | ||
280412d8 | 3335 | Variable `sql-input-ring-file-name' controls the initialization of the |
77d352a6 | 3336 | input ring history. |
95e4b2ef RS |
3337 | |
3338 | Variables `comint-output-filter-functions', a hook, and | |
3339 | `comint-scroll-to-bottom-on-input' and | |
3340 | `comint-scroll-to-bottom-on-output' control whether input and output | |
3341 | cause the window to scroll to the end of the buffer. | |
3342 | ||
3343 | If you want to make SQL buffers limited in length, add the function | |
3344 | `comint-truncate-buffer' to `comint-output-filter-functions'. | |
3345 | ||
dab100d7 | 3346 | Here is an example for your .emacs file. It keeps the SQLi buffer a |
c7055d66 | 3347 | certain length. |
95e4b2ef RS |
3348 | |
3349 | \(add-hook 'sql-interactive-mode-hook | |
3350 | \(function (lambda () | |
95e4b2ef RS |
3351 | \(setq comint-output-filter-functions 'comint-truncate-buffer)))) |
3352 | ||
3353 | Here is another example. It will always put point back to the statement | |
3354 | you entered, right above the output it created. | |
3355 | ||
801d1cb0 | 3356 | \(setq comint-output-filter-functions |
95e4b2ef | 3357 | \(function (lambda (STR) (comint-show-output))))" |
03789b21 | 3358 | (delay-mode-hooks (comint-mode)) |
7492acc9 | 3359 | |
78024f88 AS |
3360 | ;; Get the `sql-product' for this interactive session. |
3361 | (set (make-local-variable 'sql-product) | |
3362 | (or sql-interactive-product | |
3363 | sql-product)) | |
7492acc9 | 3364 | |
78024f88 | 3365 | ;; Setup the mode. |
175069ef SM |
3366 | (setq major-mode 'sql-interactive-mode) ;FIXME: Use define-derived-mode. |
3367 | (setq mode-name | |
3368 | (concat "SQLi[" (or (sql-get-product-feature sql-product :name) | |
3369 | (symbol-name sql-product)) "]")) | |
95e4b2ef | 3370 | (use-local-map sql-interactive-mode-map) |
311e7a89 | 3371 | (if sql-interactive-mode-menu |
78024f88 | 3372 | (easy-menu-add sql-interactive-mode-menu)) ; XEmacs |
95e4b2ef | 3373 | (set-syntax-table sql-mode-syntax-table) |
7492acc9 | 3374 | |
a081a529 | 3375 | ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try |
801d1cb0 AS |
3376 | ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column |
3377 | ;; will have just one quote. Therefore syntactic hilighting is | |
78024f88 AS |
3378 | ;; disabled for interactive buffers. No imenu support. |
3379 | (sql-product-font-lock t nil) | |
7492acc9 | 3380 | |
c7055d66 | 3381 | ;; Enable commenting and uncommenting of the region. |
175069ef | 3382 | (set (make-local-variable 'comment-start) "--") |
78024f88 | 3383 | ;; Abbreviation table init and case-insensitive. It is not activated |
c7055d66 | 3384 | ;; by default. |
95e4b2ef RS |
3385 | (setq local-abbrev-table sql-mode-abbrev-table) |
3386 | (setq abbrev-all-caps 1) | |
c7055d66 | 3387 | ;; Exiting the process will call sql-stop. |
9250002f | 3388 | (set-process-sentinel (get-buffer-process (current-buffer)) 'sql-stop) |
30c4d8dc MM |
3389 | ;; Save the connection name |
3390 | (make-local-variable 'sql-connection) | |
78024f88 | 3391 | ;; Create a usefull name for renaming this buffer later. |
175069ef SM |
3392 | (set (make-local-variable 'sql-alternate-buffer-name) |
3393 | (sql-make-alternate-buffer-name)) | |
78024f88 AS |
3394 | ;; User stuff. Initialize before the hook. |
3395 | (set (make-local-variable 'sql-prompt-regexp) | |
7492acc9 | 3396 | (sql-get-product-feature sql-product :prompt-regexp)) |
78024f88 | 3397 | (set (make-local-variable 'sql-prompt-length) |
7492acc9 | 3398 | (sql-get-product-feature sql-product :prompt-length)) |
3bd2cfef MM |
3399 | (set (make-local-variable 'sql-prompt-cont-regexp) |
3400 | (sql-get-product-feature sql-product :prompt-cont-regexp)) | |
3401 | (make-local-variable 'sql-output-newline-count) | |
3402 | (make-local-variable 'sql-output-by-send) | |
3403 | (add-hook 'comint-preoutput-filter-functions | |
3404 | 'sql-interactive-remove-continuation-prompt nil t) | |
78024f88 AS |
3405 | (make-local-variable 'sql-input-ring-separator) |
3406 | (make-local-variable 'sql-input-ring-file-name) | |
7492acc9 | 3407 | ;; Run the mode hook (along with comint's hooks). |
9a969196 | 3408 | (run-mode-hooks 'sql-interactive-mode-hook) |
78024f88 | 3409 | ;; Set comint based on user overrides. |
3bd2cfef MM |
3410 | (setq comint-prompt-regexp |
3411 | (if sql-prompt-cont-regexp | |
3412 | (concat "\\(" sql-prompt-regexp | |
3413 | "\\|" sql-prompt-cont-regexp "\\)") | |
3414 | sql-prompt-regexp)) | |
78024f88 | 3415 | (setq left-margin sql-prompt-length) |
7492acc9 MM |
3416 | ;; Install input sender |
3417 | (set (make-local-variable 'comint-input-sender) 'sql-input-sender) | |
77d352a6 GM |
3418 | ;; People wanting a different history file for each |
3419 | ;; buffer/process/client/whatever can change separator and file-name | |
3420 | ;; on the sql-interactive-mode-hook. | |
3421 | (setq comint-input-ring-separator sql-input-ring-separator | |
3422 | comint-input-ring-file-name sql-input-ring-file-name) | |
c7055d66 | 3423 | ;; Calling the hook before calling comint-read-input-ring allows users |
95e4b2ef | 3424 | ;; to set comint-input-ring-file-name in sql-interactive-mode-hook. |
77d352a6 | 3425 | (comint-read-input-ring t)) |
95e4b2ef RS |
3426 | |
3427 | (defun sql-stop (process event) | |
3428 | "Called when the SQL process is stopped. | |
3429 | ||
c7055d66 RS |
3430 | Writes the input history to a history file using |
3431 | `comint-write-input-ring' and inserts a short message in the SQL buffer. | |
95e4b2ef RS |
3432 | |
3433 | This function is a sentinel watching the SQL interpreter process. | |
3434 | Sentinels will always get the two parameters PROCESS and EVENT." | |
77d352a6 GM |
3435 | (comint-write-input-ring) |
3436 | (if (and (eq (current-buffer) sql-buffer) | |
3437 | (not buffer-read-only)) | |
3438 | (insert (format "\nProcess %s %s\n" process event)) | |
3439 | (message "Process %s %s" process event))) | |
95e4b2ef RS |
3440 | |
3441 | \f | |
3442 | ||
5474c40f | 3443 | ;;; Connection handling |
30c4d8dc | 3444 | |
74790210 MM |
3445 | (defun sql-read-connection (prompt &optional initial default) |
3446 | "Read a connection name." | |
3447 | (let ((completion-ignore-case t)) | |
3448 | (completing-read prompt | |
3449 | (mapcar (lambda (c) (car c)) | |
3450 | sql-connection-alist) | |
3451 | nil t initial 'sql-connection-history default))) | |
3452 | ||
30c4d8dc MM |
3453 | ;;;###autoload |
3454 | (defun sql-connect (connection) | |
3455 | "Connect to an interactive session using CONNECTION settings. | |
3456 | ||
3457 | See `sql-connection-alist' to see how to define connections and | |
3458 | their settings. | |
3459 | ||
3460 | The user will not be prompted for any login parameters if a value | |
3461 | is specified in the connection settings." | |
3462 | ||
3463 | ;; Prompt for the connection from those defined in the alist | |
3464 | (interactive | |
3465 | (if sql-connection-alist | |
74790210 | 3466 | (list (sql-read-connection "Connection: " nil '(nil))) |
30c4d8dc MM |
3467 | nil)) |
3468 | ||
3469 | ;; Are there connections defined | |
3470 | (if sql-connection-alist | |
3471 | ;; Was one selected | |
3472 | (when connection | |
3473 | ;; Get connection settings | |
d26b0ea9 | 3474 | (let ((connect-set (assoc connection sql-connection-alist))) |
30c4d8dc MM |
3475 | ;; Settings are defined |
3476 | (if connect-set | |
3477 | ;; Set the desired parameters | |
3478 | (eval `(let* | |
d26b0ea9 | 3479 | (,@(cdr connect-set) |
30c4d8dc MM |
3480 | ;; :sqli-login params variable |
3481 | (param-var (sql-get-product-feature sql-product | |
3482 | :sqli-login nil t)) | |
3483 | ;; :sqli-login params value | |
3484 | (login-params (sql-get-product-feature sql-product | |
3485 | :sqli-login)) | |
3486 | ;; which params are in the connection | |
3487 | (set-params (mapcar | |
3488 | (lambda (v) | |
3489 | (cond | |
3490 | ((eq (car v) 'sql-user) 'user) | |
3491 | ((eq (car v) 'sql-password) 'password) | |
3492 | ((eq (car v) 'sql-server) 'server) | |
3493 | ((eq (car v) 'sql-database) 'database) | |
3494 | ((eq (car v) 'sql-port) 'port) | |
3495 | (t (car v)))) | |
d26b0ea9 | 3496 | (cdr connect-set))) |
30c4d8dc | 3497 | ;; the remaining params (w/o the connection params) |
5474c40f MM |
3498 | (rem-params (sql-for-each-login |
3499 | login-params | |
74790210 | 3500 | (lambda (token plist) |
5474c40f | 3501 | (unless (member token set-params) |
74790210 MM |
3502 | (if plist |
3503 | (cons token plist) | |
5474c40f | 3504 | token))))) |
30c4d8dc MM |
3505 | ;; Remember the connection |
3506 | (sql-connection connection)) | |
3507 | ||
3508 | ;; Set the remaining parameters and start the | |
3509 | ;; interactive session | |
3510 | (eval `(let ((,param-var ',rem-params)) | |
3511 | (sql-product-interactive sql-product))))) | |
d26b0ea9 | 3512 | (message "SQL Connection <%s> does not exist" connection) |
30c4d8dc MM |
3513 | nil))) |
3514 | (message "No SQL Connections defined") | |
3515 | nil)) | |
78024f88 | 3516 | |
d26b0ea9 MM |
3517 | (defun sql-save-connection (name) |
3518 | "Captures the connection information of the current SQLi session. | |
3519 | ||
3520 | The information is appended to `sql-connection-alist' and | |
3521 | optionally is saved to the user's init file." | |
3522 | ||
3523 | (interactive "sNew connection name: ") | |
3524 | ||
3525 | (if sql-connection | |
3526 | (message "This session was started by a connection; it's already been saved.") | |
3527 | ||
3528 | (let ((login (sql-get-product-feature sql-product :sqli-login)) | |
3529 | (alist sql-connection-alist) | |
3530 | connect) | |
3531 | ||
3532 | ;; Remove the existing connection if the user says so | |
3533 | (when (and (assoc name alist) | |
3534 | (yes-or-no-p (format "Replace connection definition <%s>? " name))) | |
3535 | (setq alist (assq-delete-all name alist))) | |
3536 | ||
3537 | ;; Add the new connection if it doesn't exist | |
3538 | (if (assoc name alist) | |
3539 | (message "Connection <%s> already exists" name) | |
3540 | (setq connect | |
3541 | (append (list name) | |
5474c40f MM |
3542 | (sql-for-each-login |
3543 | `(product ,@login) | |
74790210 | 3544 | (lambda (token plist) |
5474c40f MM |
3545 | (cond |
3546 | ((eq token 'product) `(sql-product ',sql-product)) | |
3547 | ((eq token 'user) `(sql-user ,sql-user)) | |
3548 | ((eq token 'database) `(sql-database ,sql-database)) | |
3549 | ((eq token 'server) `(sql-server ,sql-server)) | |
3550 | ((eq token 'port) `(sql-port ,sql-port))))))) | |
d26b0ea9 MM |
3551 | |
3552 | (setq alist (append alist (list connect))) | |
3553 | ||
3554 | ;; confirm whether we want to save the connections | |
3555 | (if (yes-or-no-p "Save the connections for future sessions? ") | |
3556 | (customize-save-variable 'sql-connection-alist alist) | |
3557 | (customize-set-variable 'sql-connection-alist alist)))))) | |
3558 | ||
3559 | (defun sql-connection-menu-filter (tail) | |
3560 | "Generates menu entries for using each connection." | |
3561 | (append | |
3562 | (mapcar | |
3563 | (lambda (conn) | |
3564 | (vector | |
3565 | (format "Connection <%s>" (car conn)) | |
3566 | (list 'sql-connect (car conn)) | |
3567 | t)) | |
3568 | sql-connection-alist) | |
3569 | tail)) | |
3570 | ||
5474c40f MM |
3571 | \f |
3572 | ||
3573 | ;;; Entry functions for different SQL interpreters. | |
3574 | ||
3575 | ;;;###autoload | |
9250002f | 3576 | (defun sql-product-interactive (&optional product new-name) |
5474c40f MM |
3577 | "Run PRODUCT interpreter as an inferior process. |
3578 | ||
3579 | If buffer `*SQL*' exists but no process is running, make a new process. | |
3580 | If buffer exists and a process is running, just switch to buffer `*SQL*'. | |
3581 | ||
9250002f MM |
3582 | To specify the SQL product, prefix the call with |
3583 | \\[universal-argument]. To set the buffer name as well, prefix | |
3584 | the call to \\[sql-product-interactive] with | |
3585 | \\[universal-argument] \\[universal-argument]. | |
3586 | ||
5474c40f MM |
3587 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
3588 | (interactive "P") | |
3589 | ||
9250002f MM |
3590 | ;; Handle universal arguments if specified |
3591 | (when (not (or executing-kbd-macro noninteractive)) | |
a386ac70 | 3592 | (when (and (consp product) |
9250002f MM |
3593 | (not (cdr product)) |
3594 | (numberp (car product))) | |
74790210 | 3595 | (when (>= (prefix-numeric-value product) 16) |
9250002f MM |
3596 | (when (not new-name) |
3597 | (setq new-name '(4))) | |
3598 | (setq product '(4))))) | |
3599 | ||
3600 | ;; Get the value of product that we need | |
5474c40f MM |
3601 | (setq product |
3602 | (cond | |
5474c40f MM |
3603 | ((and product ; Product specified |
3604 | (symbolp product)) product) | |
74790210 MM |
3605 | ((= (prefix-numeric-value product) 4) ; C-u, prompt for product |
3606 | (sql-read-product "SQL product: " sql-product)) | |
5474c40f MM |
3607 | (t sql-product))) ; Default to sql-product |
3608 | ||
9250002f | 3609 | ;; If we have a product and it has a interactive mode |
5474c40f MM |
3610 | (if product |
3611 | (when (sql-get-product-feature product :sqli-comint-func) | |
74790210 MM |
3612 | ;; If no new name specified, try to pop to an active SQL |
3613 | ;; interactive for the same product | |
3614 | (let ((buf (sql-find-sqli-buffer product))) | |
3615 | (if (and (not new-name) buf) | |
3616 | (pop-to-buffer buf) | |
3617 | ||
3618 | ;; We have a new name or sql-buffer doesn't exist or match | |
3619 | ;; Start by remembering where we start | |
3620 | (let ((start-buffer (current-buffer)) | |
3621 | new-sqli-buffer) | |
3622 | ||
3623 | ;; Get credentials. | |
3624 | (apply 'sql-get-login (sql-get-product-feature product :sqli-login)) | |
3625 | ||
3626 | ;; Connect to database. | |
3627 | (message "Login...") | |
3628 | (funcall (sql-get-product-feature product :sqli-comint-func) | |
3629 | product | |
3630 | (sql-get-product-feature product :sqli-options)) | |
3631 | ||
3632 | ;; Set SQLi mode. | |
3633 | (setq new-sqli-buffer (current-buffer)) | |
3634 | (let ((sql-interactive-product product)) | |
3635 | (sql-interactive-mode)) | |
3636 | ||
3637 | ;; Set the new buffer name | |
3638 | (when new-name | |
3639 | (sql-rename-buffer new-name)) | |
3640 | ||
3641 | ;; Set `sql-buffer' in the new buffer and the start buffer | |
a386ac70 | 3642 | (setq sql-buffer (buffer-name new-sqli-buffer)) |
74790210 MM |
3643 | (with-current-buffer start-buffer |
3644 | (setq sql-buffer (buffer-name new-sqli-buffer)) | |
3645 | (run-hooks 'sql-set-sqli-hook)) | |
5474c40f | 3646 | |
74790210 MM |
3647 | ;; All done. |
3648 | (message "Login...done") | |
3649 | (pop-to-buffer sql-buffer))))) | |
5474c40f MM |
3650 | (message "No default SQL product defined. Set `sql-product'."))) |
3651 | ||
3652 | (defun sql-comint (product params) | |
3653 | "Set up a comint buffer to run the SQL processor. | |
3654 | ||
3655 | PRODUCT is the SQL product. PARAMS is a list of strings which are | |
3656 | passed as command line arguments." | |
9250002f MM |
3657 | (let ((program (sql-get-product-feature product :sqli-program)) |
3658 | (buf-name "SQL")) | |
74790210 MM |
3659 | ;; make sure we can find the program |
3660 | (unless (executable-find program) | |
3661 | (error "Unable to locate SQL program \'%s\'" program)) | |
9250002f | 3662 | ;; Make sure buffer name is unique |
74790210 | 3663 | (when (sql-buffer-live-p (format "*%s*" buf-name)) |
9250002f | 3664 | (setq buf-name (format "SQL-%s" product)) |
74790210 | 3665 | (when (sql-buffer-live-p (format "*%s*" buf-name)) |
9250002f | 3666 | (let ((i 1)) |
74790210 MM |
3667 | (while (sql-buffer-live-p |
3668 | (format "*%s*" | |
3669 | (setq buf-name (format "SQL-%s%d" product i)))) | |
9250002f | 3670 | (setq i (1+ i)))))) |
5474c40f | 3671 | (set-buffer |
9250002f | 3672 | (apply 'make-comint buf-name program nil params)))) |
5474c40f | 3673 | |
77d352a6 | 3674 | ;;;###autoload |
9250002f | 3675 | (defun sql-oracle (&optional buffer) |
95e4b2ef RS |
3676 | "Run sqlplus by Oracle as an inferior process. |
3677 | ||
dab100d7 | 3678 | If buffer `*SQL*' exists but no process is running, make a new process. |
95e4b2ef RS |
3679 | If buffer exists and a process is running, just switch to buffer |
3680 | `*SQL*'. | |
3681 | ||
dab100d7 RS |
3682 | Interpreter used comes from variable `sql-oracle-program'. Login uses |
3683 | the variables `sql-user', `sql-password', and `sql-database' as | |
9ef3882f GM |
3684 | defaults, if set. Additional command line parameters can be stored in |
3685 | the list `sql-oracle-options'. | |
95e4b2ef | 3686 | |
063c6324 | 3687 | The buffer is put in SQL interactive mode, giving commands for sending |
95e4b2ef RS |
3688 | input. See `sql-interactive-mode'. |
3689 | ||
9250002f MM |
3690 | To set the buffer name directly, use \\[universal-argument] |
3691 | before \\[sql-oracle]. Once session has started, | |
3692 | \\[sql-rename-buffer] can be called separately to rename the | |
3693 | buffer. | |
3694 | ||
95e4b2ef RS |
3695 | To specify a coding system for converting non-ASCII characters |
3696 | in the input and output to the process, use \\[universal-coding-system-argument] | |
3697 | before \\[sql-oracle]. You can also specify this with \\[set-buffer-process-coding-system] | |
3698 | in the SQL buffer, after you start the process. | |
3699 | The default comes from `process-coding-system-alist' and | |
3700 | `default-process-coding-system'. | |
3701 | ||
3702 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
3703 | (interactive "P") |
3704 | (sql-product-interactive 'oracle buffer)) | |
78024f88 | 3705 | |
30c4d8dc | 3706 | (defun sql-comint-oracle (product options) |
7492acc9 | 3707 | "Create comint buffer and connect to Oracle." |
78024f88 AS |
3708 | ;; Produce user/password@database construct. Password without user |
3709 | ;; is meaningless; database without user/password is meaningless, | |
3710 | ;; because "@param" will ask sqlplus to interpret the script | |
3711 | ;; "param". | |
7492acc9 MM |
3712 | (let ((parameter nil)) |
3713 | (if (not (string= "" sql-user)) | |
3714 | (if (not (string= "" sql-password)) | |
3715 | (setq parameter (concat sql-user "/" sql-password)) | |
3716 | (setq parameter sql-user))) | |
78024f88 AS |
3717 | (if (and parameter (not (string= "" sql-database))) |
3718 | (setq parameter (concat parameter "@" sql-database))) | |
7492acc9 MM |
3719 | (if parameter |
3720 | (setq parameter (nconc (list parameter) options)) | |
3721 | (setq parameter options)) | |
30c4d8dc | 3722 | (sql-comint product parameter))) |
95e4b2ef RS |
3723 | |
3724 | \f | |
3725 | ||
77d352a6 | 3726 | ;;;###autoload |
9250002f | 3727 | (defun sql-sybase (&optional buffer) |
c38762fd | 3728 | "Run isql by Sybase as an inferior process. |
95e4b2ef | 3729 | |
dab100d7 | 3730 | If buffer `*SQL*' exists but no process is running, make a new process. |
95e4b2ef RS |
3731 | If buffer exists and a process is running, just switch to buffer |
3732 | `*SQL*'. | |
3733 | ||
3734 | Interpreter used comes from variable `sql-sybase-program'. Login uses | |
9b5360aa | 3735 | the variables `sql-server', `sql-user', `sql-password', and |
7a65c85c GM |
3736 | `sql-database' as defaults, if set. Additional command line parameters |
3737 | can be stored in the list `sql-sybase-options'. | |
95e4b2ef | 3738 | |
063c6324 | 3739 | The buffer is put in SQL interactive mode, giving commands for sending |
95e4b2ef RS |
3740 | input. See `sql-interactive-mode'. |
3741 | ||
9250002f MM |
3742 | To set the buffer name directly, use \\[universal-argument] |
3743 | before \\[sql-sybase]. Once session has started, | |
3744 | \\[sql-rename-buffer] can be called separately to rename the | |
3745 | buffer. | |
3746 | ||
95e4b2ef RS |
3747 | To specify a coding system for converting non-ASCII characters |
3748 | in the input and output to the process, use \\[universal-coding-system-argument] | |
3749 | before \\[sql-sybase]. You can also specify this with \\[set-buffer-process-coding-system] | |
3750 | in the SQL buffer, after you start the process. | |
3751 | The default comes from `process-coding-system-alist' and | |
3752 | `default-process-coding-system'. | |
3753 | ||
3754 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
3755 | (interactive "P") |
3756 | (sql-product-interactive 'sybase buffer)) | |
78024f88 | 3757 | |
30c4d8dc | 3758 | (defun sql-comint-sybase (product options) |
7492acc9 | 3759 | "Create comint buffer and connect to Sybase." |
78024f88 AS |
3760 | ;; Put all parameters to the program (if defined) in a list and call |
3761 | ;; make-comint. | |
7492acc9 | 3762 | (let ((params options)) |
78024f88 AS |
3763 | (if (not (string= "" sql-server)) |
3764 | (setq params (append (list "-S" sql-server) params))) | |
3765 | (if (not (string= "" sql-database)) | |
3766 | (setq params (append (list "-D" sql-database) params))) | |
3767 | (if (not (string= "" sql-password)) | |
3768 | (setq params (append (list "-P" sql-password) params))) | |
3769 | (if (not (string= "" sql-user)) | |
3770 | (setq params (append (list "-U" sql-user) params))) | |
30c4d8dc | 3771 | (sql-comint product params))) |
95e4b2ef RS |
3772 | |
3773 | \f | |
3774 | ||
77d352a6 | 3775 | ;;;###autoload |
9250002f | 3776 | (defun sql-informix (&optional buffer) |
95e4b2ef RS |
3777 | "Run dbaccess by Informix as an inferior process. |
3778 | ||
dab100d7 | 3779 | If buffer `*SQL*' exists but no process is running, make a new process. |
95e4b2ef RS |
3780 | If buffer exists and a process is running, just switch to buffer |
3781 | `*SQL*'. | |
3782 | ||
3783 | Interpreter used comes from variable `sql-informix-program'. Login uses | |
3784 | the variable `sql-database' as default, if set. | |
3785 | ||
063c6324 | 3786 | The buffer is put in SQL interactive mode, giving commands for sending |
95e4b2ef RS |
3787 | input. See `sql-interactive-mode'. |
3788 | ||
9250002f MM |
3789 | To set the buffer name directly, use \\[universal-argument] |
3790 | before \\[sql-informix]. Once session has started, | |
3791 | \\[sql-rename-buffer] can be called separately to rename the | |
3792 | buffer. | |
3793 | ||
95e4b2ef RS |
3794 | To specify a coding system for converting non-ASCII characters |
3795 | in the input and output to the process, use \\[universal-coding-system-argument] | |
3796 | before \\[sql-informix]. You can also specify this with \\[set-buffer-process-coding-system] | |
3797 | in the SQL buffer, after you start the process. | |
3798 | The default comes from `process-coding-system-alist' and | |
3799 | `default-process-coding-system'. | |
3800 | ||
3801 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
3802 | (interactive "P") |
3803 | (sql-product-interactive 'informix buffer)) | |
78024f88 | 3804 | |
30c4d8dc | 3805 | (defun sql-comint-informix (product options) |
7492acc9 | 3806 | "Create comint buffer and connect to Informix." |
78024f88 | 3807 | ;; username and password are ignored. |
7492acc9 MM |
3808 | (let ((db (if (string= "" sql-database) |
3809 | "-" | |
3810 | (if (string= "" sql-server) | |
3811 | sql-database | |
3812 | (concat sql-database "@" sql-server))))) | |
30c4d8dc | 3813 | (sql-comint product (append `(,db "-") options)))) |
a081a529 RS |
3814 | |
3815 | \f | |
3816 | ||
5d538ce3 | 3817 | ;;;###autoload |
9250002f | 3818 | (defun sql-sqlite (&optional buffer) |
5d538ce3 JB |
3819 | "Run sqlite as an inferior process. |
3820 | ||
3821 | SQLite is free software. | |
3822 | ||
3823 | If buffer `*SQL*' exists but no process is running, make a new process. | |
3824 | If buffer exists and a process is running, just switch to buffer | |
3825 | `*SQL*'. | |
3826 | ||
3827 | Interpreter used comes from variable `sql-sqlite-program'. Login uses | |
3828 | the variables `sql-user', `sql-password', `sql-database', and | |
3829 | `sql-server' as defaults, if set. Additional command line parameters | |
3830 | can be stored in the list `sql-sqlite-options'. | |
3831 | ||
063c6324 | 3832 | The buffer is put in SQL interactive mode, giving commands for sending |
5d538ce3 JB |
3833 | input. See `sql-interactive-mode'. |
3834 | ||
9250002f MM |
3835 | To set the buffer name directly, use \\[universal-argument] |
3836 | before \\[sql-sqlite]. Once session has started, | |
3837 | \\[sql-rename-buffer] can be called separately to rename the | |
3838 | buffer. | |
3839 | ||
5d538ce3 JB |
3840 | To specify a coding system for converting non-ASCII characters |
3841 | in the input and output to the process, use \\[universal-coding-system-argument] | |
3842 | before \\[sql-sqlite]. You can also specify this with \\[set-buffer-process-coding-system] | |
3843 | in the SQL buffer, after you start the process. | |
3844 | The default comes from `process-coding-system-alist' and | |
3845 | `default-process-coding-system'. | |
3846 | ||
3847 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
3848 | (interactive "P") |
3849 | (sql-product-interactive 'sqlite buffer)) | |
78024f88 | 3850 | |
30c4d8dc | 3851 | (defun sql-comint-sqlite (product options) |
7492acc9 | 3852 | "Create comint buffer and connect to SQLite." |
78024f88 AS |
3853 | ;; Put all parameters to the program (if defined) in a list and call |
3854 | ;; make-comint. | |
3855 | (let ((params)) | |
3856 | (if (not (string= "" sql-database)) | |
5474c40f MM |
3857 | (setq params (append (list (expand-file-name sql-database)) |
3858 | params))) | |
7492acc9 | 3859 | (setq params (append options params)) |
30c4d8dc | 3860 | (sql-comint product params))) |
5d538ce3 JB |
3861 | |
3862 | \f | |
3863 | ||
77d352a6 | 3864 | ;;;###autoload |
9250002f | 3865 | (defun sql-mysql (&optional buffer) |
a081a529 | 3866 | "Run mysql by TcX as an inferior process. |
dab100d7 | 3867 | |
058fb10a | 3868 | Mysql versions 3.23 and up are free software. |
a081a529 | 3869 | |
50842164 | 3870 | If buffer `*SQL*' exists but no process is running, make a new process. |
a081a529 RS |
3871 | If buffer exists and a process is running, just switch to buffer |
3872 | `*SQL*'. | |
3873 | ||
3874 | Interpreter used comes from variable `sql-mysql-program'. Login uses | |
dab100d7 | 3875 | the variables `sql-user', `sql-password', `sql-database', and |
7a65c85c GM |
3876 | `sql-server' as defaults, if set. Additional command line parameters |
3877 | can be stored in the list `sql-mysql-options'. | |
a081a529 | 3878 | |
063c6324 | 3879 | The buffer is put in SQL interactive mode, giving commands for sending |
a081a529 RS |
3880 | input. See `sql-interactive-mode'. |
3881 | ||
9250002f MM |
3882 | To set the buffer name directly, use \\[universal-argument] |
3883 | before \\[sql-mysql]. Once session has started, | |
3884 | \\[sql-rename-buffer] can be called separately to rename the | |
3885 | buffer. | |
3886 | ||
a081a529 RS |
3887 | To specify a coding system for converting non-ASCII characters |
3888 | in the input and output to the process, use \\[universal-coding-system-argument] | |
dab100d7 | 3889 | before \\[sql-mysql]. You can also specify this with \\[set-buffer-process-coding-system] |
a081a529 RS |
3890 | in the SQL buffer, after you start the process. |
3891 | The default comes from `process-coding-system-alist' and | |
3892 | `default-process-coding-system'. | |
3893 | ||
3894 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
3895 | (interactive "P") |
3896 | (sql-product-interactive 'mysql buffer)) | |
78024f88 | 3897 | |
30c4d8dc | 3898 | (defun sql-comint-mysql (product options) |
7492acc9 | 3899 | "Create comint buffer and connect to MySQL." |
78024f88 AS |
3900 | ;; Put all parameters to the program (if defined) in a list and call |
3901 | ;; make-comint. | |
3902 | (let ((params)) | |
3903 | (if (not (string= "" sql-database)) | |
3904 | (setq params (append (list sql-database) params))) | |
3905 | (if (not (string= "" sql-server)) | |
3906 | (setq params (append (list (concat "--host=" sql-server)) params))) | |
9250002f | 3907 | (if (not (= 0 sql-port)) |
7492acc9 | 3908 | (setq params (append (list (concat "--port=" (number-to-string sql-port))) params))) |
78024f88 AS |
3909 | (if (not (string= "" sql-password)) |
3910 | (setq params (append (list (concat "--password=" sql-password)) params))) | |
3911 | (if (not (string= "" sql-user)) | |
3912 | (setq params (append (list (concat "--user=" sql-user)) params))) | |
7492acc9 | 3913 | (setq params (append options params)) |
30c4d8dc | 3914 | (sql-comint product params))) |
95e4b2ef RS |
3915 | |
3916 | \f | |
3917 | ||
77d352a6 | 3918 | ;;;###autoload |
9250002f | 3919 | (defun sql-solid (&optional buffer) |
dab100d7 RS |
3920 | "Run solsql by Solid as an inferior process. |
3921 | ||
3922 | If buffer `*SQL*' exists but no process is running, make a new process. | |
3923 | If buffer exists and a process is running, just switch to buffer | |
3924 | `*SQL*'. | |
3925 | ||
3926 | Interpreter used comes from variable `sql-solid-program'. Login uses | |
3927 | the variables `sql-user', `sql-password', and `sql-server' as | |
3928 | defaults, if set. | |
3929 | ||
063c6324 | 3930 | The buffer is put in SQL interactive mode, giving commands for sending |
dab100d7 RS |
3931 | input. See `sql-interactive-mode'. |
3932 | ||
9250002f MM |
3933 | To set the buffer name directly, use \\[universal-argument] |
3934 | before \\[sql-solid]. Once session has started, | |
3935 | \\[sql-rename-buffer] can be called separately to rename the | |
3936 | buffer. | |
3937 | ||
dab100d7 RS |
3938 | To specify a coding system for converting non-ASCII characters |
3939 | in the input and output to the process, use \\[universal-coding-system-argument] | |
3940 | before \\[sql-solid]. You can also specify this with \\[set-buffer-process-coding-system] | |
3941 | in the SQL buffer, after you start the process. | |
3942 | The default comes from `process-coding-system-alist' and | |
3943 | `default-process-coding-system'. | |
3944 | ||
3945 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
3946 | (interactive "P") |
3947 | (sql-product-interactive 'solid buffer)) | |
78024f88 | 3948 | |
30c4d8dc | 3949 | (defun sql-comint-solid (product options) |
7492acc9 | 3950 | "Create comint buffer and connect to Solid." |
78024f88 AS |
3951 | ;; Put all parameters to the program (if defined) in a list and call |
3952 | ;; make-comint. | |
7492acc9 | 3953 | (let ((params options)) |
78024f88 AS |
3954 | ;; It only makes sense if both username and password are there. |
3955 | (if (not (or (string= "" sql-user) | |
3956 | (string= "" sql-password))) | |
3957 | (setq params (append (list sql-user sql-password) params))) | |
3958 | (if (not (string= "" sql-server)) | |
3959 | (setq params (append (list sql-server) params))) | |
30c4d8dc | 3960 | (sql-comint product params))) |
dab100d7 RS |
3961 | |
3962 | \f | |
3963 | ||
77d352a6 | 3964 | ;;;###autoload |
9250002f | 3965 | (defun sql-ingres (&optional buffer) |
95e4b2ef RS |
3966 | "Run sql by Ingres as an inferior process. |
3967 | ||
dab100d7 | 3968 | If buffer `*SQL*' exists but no process is running, make a new process. |
95e4b2ef RS |
3969 | If buffer exists and a process is running, just switch to buffer |
3970 | `*SQL*'. | |
3971 | ||
3972 | Interpreter used comes from variable `sql-ingres-program'. Login uses | |
3973 | the variable `sql-database' as default, if set. | |
3974 | ||
063c6324 | 3975 | The buffer is put in SQL interactive mode, giving commands for sending |
95e4b2ef RS |
3976 | input. See `sql-interactive-mode'. |
3977 | ||
9250002f MM |
3978 | To set the buffer name directly, use \\[universal-argument] |
3979 | before \\[sql-ingres]. Once session has started, | |
3980 | \\[sql-rename-buffer] can be called separately to rename the | |
3981 | buffer. | |
3982 | ||
95e4b2ef RS |
3983 | To specify a coding system for converting non-ASCII characters |
3984 | in the input and output to the process, use \\[universal-coding-system-argument] | |
3985 | before \\[sql-ingres]. You can also specify this with \\[set-buffer-process-coding-system] | |
3986 | in the SQL buffer, after you start the process. | |
3987 | The default comes from `process-coding-system-alist' and | |
3988 | `default-process-coding-system'. | |
3989 | ||
3990 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
3991 | (interactive "P") |
3992 | (sql-product-interactive 'ingres buffer)) | |
78024f88 | 3993 | |
30c4d8dc | 3994 | (defun sql-comint-ingres (product options) |
7492acc9 | 3995 | "Create comint buffer and connect to Ingres." |
78024f88 | 3996 | ;; username and password are ignored. |
30c4d8dc | 3997 | (sql-comint product |
7492acc9 MM |
3998 | (append (if (string= "" sql-database) |
3999 | nil | |
4000 | (list sql-database)) | |
4001 | options))) | |
95e4b2ef RS |
4002 | |
4003 | \f | |
4004 | ||
77d352a6 | 4005 | ;;;###autoload |
9250002f | 4006 | (defun sql-ms (&optional buffer) |
78024f88 | 4007 | "Run osql by Microsoft as an inferior process. |
95e4b2ef | 4008 | |
dab100d7 | 4009 | If buffer `*SQL*' exists but no process is running, make a new process. |
95e4b2ef RS |
4010 | If buffer exists and a process is running, just switch to buffer |
4011 | `*SQL*'. | |
4012 | ||
4013 | Interpreter used comes from variable `sql-ms-program'. Login uses the | |
dab100d7 | 4014 | variables `sql-user', `sql-password', `sql-database', and `sql-server' |
f4df536d JB |
4015 | as defaults, if set. Additional command line parameters can be stored |
4016 | in the list `sql-ms-options'. | |
95e4b2ef | 4017 | |
063c6324 | 4018 | The buffer is put in SQL interactive mode, giving commands for sending |
95e4b2ef RS |
4019 | input. See `sql-interactive-mode'. |
4020 | ||
9250002f MM |
4021 | To set the buffer name directly, use \\[universal-argument] |
4022 | before \\[sql-ms]. Once session has started, | |
4023 | \\[sql-rename-buffer] can be called separately to rename the | |
4024 | buffer. | |
4025 | ||
95e4b2ef RS |
4026 | To specify a coding system for converting non-ASCII characters |
4027 | in the input and output to the process, use \\[universal-coding-system-argument] | |
dab100d7 | 4028 | before \\[sql-ms]. You can also specify this with \\[set-buffer-process-coding-system] |
95e4b2ef RS |
4029 | in the SQL buffer, after you start the process. |
4030 | The default comes from `process-coding-system-alist' and | |
4031 | `default-process-coding-system'. | |
4032 | ||
4033 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
4034 | (interactive "P") |
4035 | (sql-product-interactive 'ms buffer)) | |
78024f88 | 4036 | |
30c4d8dc | 4037 | (defun sql-comint-ms (product options) |
7492acc9 | 4038 | "Create comint buffer and connect to Microsoft SQL Server." |
78024f88 AS |
4039 | ;; Put all parameters to the program (if defined) in a list and call |
4040 | ;; make-comint. | |
7492acc9 | 4041 | (let ((params options)) |
78024f88 | 4042 | (if (not (string= "" sql-server)) |
95e4b2ef | 4043 | (setq params (append (list "-S" sql-server) params))) |
78024f88 | 4044 | (if (not (string= "" sql-database)) |
95e4b2ef | 4045 | (setq params (append (list "-d" sql-database) params))) |
78024f88 AS |
4046 | (if (not (string= "" sql-user)) |
4047 | (setq params (append (list "-U" sql-user) params))) | |
4048 | (if (not (string= "" sql-password)) | |
4049 | (setq params (append (list "-P" sql-password) params)) | |
4050 | (if (string= "" sql-user) | |
4051 | ;; if neither user nor password is provided, use system | |
4052 | ;; credentials. | |
4053 | (setq params (append (list "-E") params)) | |
4054 | ;; If -P is passed to ISQL as the last argument without a | |
4055 | ;; password, it's considered null. | |
4056 | (setq params (append params (list "-P"))))) | |
30c4d8dc | 4057 | (sql-comint product params))) |
95e4b2ef | 4058 | |
95e4b2ef RS |
4059 | \f |
4060 | ||
4061 | ;;;###autoload | |
9250002f | 4062 | (defun sql-postgres (&optional buffer) |
95e4b2ef RS |
4063 | "Run psql by Postgres as an inferior process. |
4064 | ||
dab100d7 | 4065 | If buffer `*SQL*' exists but no process is running, make a new process. |
95e4b2ef RS |
4066 | If buffer exists and a process is running, just switch to buffer |
4067 | `*SQL*'. | |
4068 | ||
4069 | Interpreter used comes from variable `sql-postgres-program'. Login uses | |
c04bb32e | 4070 | the variables `sql-database' and `sql-server' as default, if set. |
7a65c85c GM |
4071 | Additional command line parameters can be stored in the list |
4072 | `sql-postgres-options'. | |
95e4b2ef | 4073 | |
063c6324 | 4074 | The buffer is put in SQL interactive mode, giving commands for sending |
95e4b2ef RS |
4075 | input. See `sql-interactive-mode'. |
4076 | ||
9250002f MM |
4077 | To set the buffer name directly, use \\[universal-argument] |
4078 | before \\[sql-postgres]. Once session has started, | |
4079 | \\[sql-rename-buffer] can be called separately to rename the | |
4080 | buffer. | |
4081 | ||
95e4b2ef RS |
4082 | To specify a coding system for converting non-ASCII characters |
4083 | in the input and output to the process, use \\[universal-coding-system-argument] | |
4084 | before \\[sql-postgres]. You can also specify this with \\[set-buffer-process-coding-system] | |
4085 | in the SQL buffer, after you start the process. | |
4086 | The default comes from `process-coding-system-alist' and | |
801d1cb0 | 4087 | `default-process-coding-system'. If your output lines end with ^M, |
95e4b2ef RS |
4088 | your might try undecided-dos as a coding system. If this doesn't help, |
4089 | Try to set `comint-output-filter-functions' like this: | |
4090 | ||
4091 | \(setq comint-output-filter-functions (append comint-output-filter-functions | |
4092 | '(comint-strip-ctrl-m))) | |
4093 | ||
4094 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
4095 | (interactive "P") |
4096 | (sql-product-interactive 'postgres buffer)) | |
78024f88 | 4097 | |
30c4d8dc | 4098 | (defun sql-comint-postgres (product options) |
7492acc9 | 4099 | "Create comint buffer and connect to Postgres." |
78024f88 AS |
4100 | ;; username and password are ignored. Mark Stosberg suggest to add |
4101 | ;; the database at the end. Jason Beegan suggest using --pset and | |
4102 | ;; pager=off instead of \\o|cat. The later was the solution by | |
4103 | ;; Gregor Zych. Jason's suggestion is the default value for | |
4104 | ;; sql-postgres-options. | |
7492acc9 | 4105 | (let ((params options)) |
78024f88 AS |
4106 | (if (not (string= "" sql-database)) |
4107 | (setq params (append params (list sql-database)))) | |
4108 | (if (not (string= "" sql-server)) | |
4109 | (setq params (append (list "-h" sql-server) params))) | |
9fd8cb36 SM |
4110 | (if (not (string= "" sql-user)) |
4111 | (setq params (append (list "-U" sql-user) params))) | |
74790210 MM |
4112 | (if (not (= 0 sql-port)) |
4113 | (setq params (append (list "-p" sql-port) params))) | |
30c4d8dc | 4114 | (sql-comint product params))) |
95e4b2ef | 4115 | |
eb3f61dd GM |
4116 | \f |
4117 | ||
4118 | ;;;###autoload | |
9250002f | 4119 | (defun sql-interbase (&optional buffer) |
eb3f61dd GM |
4120 | "Run isql by Interbase as an inferior process. |
4121 | ||
4122 | If buffer `*SQL*' exists but no process is running, make a new process. | |
4123 | If buffer exists and a process is running, just switch to buffer | |
4124 | `*SQL*'. | |
4125 | ||
4126 | Interpreter used comes from variable `sql-interbase-program'. Login | |
4127 | uses the variables `sql-user', `sql-password', and `sql-database' as | |
4128 | defaults, if set. | |
4129 | ||
063c6324 | 4130 | The buffer is put in SQL interactive mode, giving commands for sending |
eb3f61dd GM |
4131 | input. See `sql-interactive-mode'. |
4132 | ||
9250002f MM |
4133 | To set the buffer name directly, use \\[universal-argument] |
4134 | before \\[sql-interbase]. Once session has started, | |
4135 | \\[sql-rename-buffer] can be called separately to rename the | |
4136 | buffer. | |
4137 | ||
eb3f61dd GM |
4138 | To specify a coding system for converting non-ASCII characters |
4139 | in the input and output to the process, use \\[universal-coding-system-argument] | |
4140 | before \\[sql-interbase]. You can also specify this with \\[set-buffer-process-coding-system] | |
4141 | in the SQL buffer, after you start the process. | |
4142 | The default comes from `process-coding-system-alist' and | |
4143 | `default-process-coding-system'. | |
4144 | ||
4145 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
4146 | (interactive "P") |
4147 | (sql-product-interactive 'interbase buffer)) | |
78024f88 | 4148 | |
30c4d8dc | 4149 | (defun sql-comint-interbase (product options) |
7492acc9 | 4150 | "Create comint buffer and connect to Interbase." |
78024f88 AS |
4151 | ;; Put all parameters to the program (if defined) in a list and call |
4152 | ;; make-comint. | |
7492acc9 | 4153 | (let ((params options)) |
78024f88 AS |
4154 | (if (not (string= "" sql-user)) |
4155 | (setq params (append (list "-u" sql-user) params))) | |
4156 | (if (not (string= "" sql-password)) | |
4157 | (setq params (append (list "-p" sql-password) params))) | |
4158 | (if (not (string= "" sql-database)) | |
4159 | (setq params (cons sql-database params))) ; add to the front! | |
30c4d8dc | 4160 | (sql-comint product params))) |
eb3f61dd | 4161 | |
624ef9b3 GM |
4162 | \f |
4163 | ||
4164 | ;;;###autoload | |
9250002f | 4165 | (defun sql-db2 (&optional buffer) |
624ef9b3 GM |
4166 | "Run db2 by IBM as an inferior process. |
4167 | ||
4168 | If buffer `*SQL*' exists but no process is running, make a new process. | |
4169 | If buffer exists and a process is running, just switch to buffer | |
4170 | `*SQL*'. | |
4171 | ||
4172 | Interpreter used comes from variable `sql-db2-program'. There is not | |
4173 | automatic login. | |
4174 | ||
063c6324 | 4175 | The buffer is put in SQL interactive mode, giving commands for sending |
624ef9b3 GM |
4176 | input. See `sql-interactive-mode'. |
4177 | ||
aa88e662 GM |
4178 | If you use \\[sql-accumulate-and-indent] to send multiline commands to |
4179 | db2, newlines will be escaped if necessary. If you don't want that, set | |
4180 | `comint-input-sender' back to `comint-simple-send' by writing an after | |
4181 | advice. See the elisp manual for more information. | |
624ef9b3 | 4182 | |
9250002f MM |
4183 | To set the buffer name directly, use \\[universal-argument] |
4184 | before \\[sql-db2]. Once session has started, | |
4185 | \\[sql-rename-buffer] can be called separately to rename the | |
4186 | buffer. | |
4187 | ||
624ef9b3 GM |
4188 | To specify a coding system for converting non-ASCII characters |
4189 | in the input and output to the process, use \\[universal-coding-system-argument] | |
4190 | before \\[sql-db2]. You can also specify this with \\[set-buffer-process-coding-system] | |
4191 | in the SQL buffer, after you start the process. | |
4192 | The default comes from `process-coding-system-alist' and | |
4193 | `default-process-coding-system'. | |
4194 | ||
4195 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
9250002f MM |
4196 | (interactive "P") |
4197 | (sql-product-interactive 'db2 buffer)) | |
78024f88 | 4198 | |
30c4d8dc | 4199 | (defun sql-comint-db2 (product options) |
7492acc9 | 4200 | "Create comint buffer and connect to DB2." |
78024f88 AS |
4201 | ;; Put all parameters to the program (if defined) in a list and call |
4202 | ;; make-comint. | |
30c4d8dc | 4203 | (sql-comint product options) |
7492acc9 | 4204 | ) |
624ef9b3 | 4205 | |
f4df536d | 4206 | ;;;###autoload |
9250002f | 4207 | (defun sql-linter (&optional buffer) |
f4df536d JB |
4208 | "Run inl by RELEX as an inferior process. |
4209 | ||
4210 | If buffer `*SQL*' exists but no process is running, make a new process. | |
4211 | If buffer exists and a process is running, just switch to buffer | |
4212 | `*SQL*'. | |
4213 | ||
4214 | Interpreter used comes from variable `sql-linter-program' - usually `inl'. | |
4215 | Login uses the variables `sql-user', `sql-password', `sql-database' and | |
4216 | `sql-server' as defaults, if set. Additional command line parameters | |
7492acc9 | 4217 | can be stored in the list `sql-linter-options'. Run inl -h to get help on |
f4df536d JB |
4218 | parameters. |
4219 | ||
4220 | `sql-database' is used to set the LINTER_MBX environment variable for | |
4221 | local connections, `sql-server' refers to the server name from the | |
4222 | `nodetab' file for the network connection (dbc_tcp or friends must run | |
4223 | for this to work). If `sql-password' is an empty string, inl will use | |
4224 | an empty password. | |
4225 | ||
063c6324 | 4226 | The buffer is put in SQL interactive mode, giving commands for sending |
f4df536d JB |
4227 | input. See `sql-interactive-mode'. |
4228 | ||
9250002f MM |
4229 | To set the buffer name directly, use \\[universal-argument] |
4230 | before \\[sql-linter]. Once session has started, | |
4231 | \\[sql-rename-buffer] can be called separately to rename the | |
4232 | buffer. | |
4233 | ||
f4df536d | 4234 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
9250002f MM |
4235 | (interactive "P") |
4236 | (sql-product-interactive 'linter buffer)) | |
78024f88 | 4237 | |
30c4d8dc | 4238 | (defun sql-comint-linter (product options) |
7492acc9 | 4239 | "Create comint buffer and connect to Linter." |
78024f88 AS |
4240 | ;; Put all parameters to the program (if defined) in a list and call |
4241 | ;; make-comint. | |
7492acc9 MM |
4242 | (let ((params options) |
4243 | (login nil) | |
4244 | (old-mbx (getenv "LINTER_MBX"))) | |
78024f88 AS |
4245 | (if (not (string= "" sql-user)) |
4246 | (setq login (concat sql-user "/" sql-password))) | |
4247 | (setq params (append (list "-u" login) params)) | |
4248 | (if (not (string= "" sql-server)) | |
4249 | (setq params (append (list "-n" sql-server) params))) | |
4250 | (if (string= "" sql-database) | |
4251 | (setenv "LINTER_MBX" nil) | |
4252 | (setenv "LINTER_MBX" sql-database)) | |
30c4d8dc | 4253 | (sql-comint product params) |
78024f88 | 4254 | (setenv "LINTER_MBX" old-mbx))) |
f4df536d JB |
4255 | |
4256 | \f | |
4257 | ||
95e4b2ef RS |
4258 | (provide 'sql) |
4259 | ||
4260 | ;;; sql.el ends here | |
7492acc9 | 4261 |