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