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