Mercurial > emacs
comparison lisp/progmodes/sql.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 893d44670df9 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; sql.el --- specialized comint.el for SQL interpreters | 1 ;;; sql.el --- specialized comint.el for SQL interpreters |
2 | 2 |
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 |
4 ;; Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Author: Alex Schroeder <alex@gnu.org> | 6 ;; Author: Alex Schroeder <alex@gnu.org> |
6 ;; Maintainer: Alex Schroeder <alex@gnu.org> | 7 ;; Maintainer: Michael Mauger <mmaug@yahoo.com> |
7 ;; Version: 1.7.0 | 8 ;; Version: 2.0.1 |
8 ;; Keywords: comm languages processes | 9 ;; Keywords: comm languages processes |
10 ;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el | |
9 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode | 11 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode |
10 | 12 |
11 ;; This file is part of GNU Emacs. | 13 ;; This file is part of GNU Emacs. |
12 | 14 |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | 15 ;; GNU Emacs is free software; you can redistribute it and/or modify |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 ;; GNU General Public License for more details. | 23 ;; GNU General Public License for more details. |
22 | 24 |
23 ;; You should have received a copy of the GNU General Public License | 25 ;; You should have received a copy of the GNU General Public License |
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 26 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02111-1307, USA. | 28 ;; Boston, MA 02110-1301, USA. |
27 | 29 |
28 ;;; Commentary: | 30 ;;; Commentary: |
29 | 31 |
30 ;; Please send bug reports and bug fixes to the mailing list at | 32 ;; Please send bug reports and bug fixes to the mailing list at |
31 ;; sql.el@gnu.org. If you want to subscribe to the mailing list, send | 33 ;; sql.el@gnu.org. If you want to subscribe to the mailing list, send |
76 ;; and the custom package | 78 ;; and the custom package |
77 ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>. | 79 ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>. |
78 | 80 |
79 ;;; Bugs: | 81 ;;; Bugs: |
80 | 82 |
81 ;; Using sql-ms (isql by Microsoft): When commands with syntax errors | 83 ;; sql-ms now uses osql instead of isql. Osql flushes its error |
82 ;; or execution errors are executed, there is no server feedback. | 84 ;; stream more frequently than isql so that error messages are |
83 ;; This happens in stored procedures for example. The server messages | 85 ;; available. There is no prompt and some output still is buffered. |
84 ;; only appear after the process is exited. This makes things | 86 ;; This improves the interaction under Emacs but it still is somewhat |
85 ;; somewhat unreliable. | 87 ;; awkward. |
88 | |
89 ;; Quoted identifiers are not supported for hilighting. Most | |
90 ;; databases support the use of double quoted strings in place of | |
91 ;; identifiers; ms (Microsoft SQLServer) also supports identifiers | |
92 ;; enclosed within brackets []. | |
86 | 93 |
87 ;; ChangeLog available on request. | 94 ;; ChangeLog available on request. |
95 | |
96 ;;; Product Support: | |
97 | |
98 ;; To add support for additional SQL products the following steps | |
99 ;; must be followed ("xyz" is the name of the product in the examples | |
100 ;; below): | |
101 | |
102 ;; 1) Add the product to `sql-product' choice list. | |
103 | |
104 ;; (const :tag "XyzDB" xyz) | |
105 | |
106 ;; 2) Add an entry to the `sql-product-alist' list. | |
107 | |
108 ;; (xyz | |
109 ;; :font-lock sql-mode-xyz-font-lock-keywords | |
110 ;; :sqli-login (user password server database) | |
111 ;; :sqli-connect sql-connect-xyz | |
112 ;; :sqli-prompt-regexp "^xyzdb> " | |
113 ;; :sqli-prompt-length 7 | |
114 ;; :sqli-input-sender nil | |
115 ;; :syntax-alist ((?# . "w"))) | |
116 | |
117 ;; 3) Add customizable values for the product interpreter and options. | |
118 | |
119 ;; ;; Customization for XyzDB | |
120 ;; | |
121 ;; (defcustom sql-xyz-program "ixyz" | |
122 ;; "*Command to start ixyz by XyzDB." | |
123 ;; :type 'file | |
124 ;; :group 'SQL) | |
125 ;; | |
126 ;; (defcustom sql-xyz-options '("-X" "-Y" "-Z") | |
127 ;; "*List of additional options for `sql-xyz-program'." | |
128 ;; :type '(repeat string) | |
129 ;; :group 'SQL) | |
130 | |
131 ;; 4) Add an entry to SQL->Product submenu. | |
132 | |
133 ;; ["XyzDB" sql-highlight-xyz-keywords | |
134 ;; :style radio | |
135 ;; :selected (eq sql-product 'xyz)] | |
136 | |
137 ;; 5) Add the font-lock specifications. At a minimum, default to | |
138 ;; using ANSI keywords. See sql-mode-oracle-font-lock-keywords for | |
139 ;; a more complex example. | |
140 | |
141 ;; (defvar sql-mode-xyz-font-lock-keywords nil | |
142 ;; "XyzDB SQL keywords used by font-lock.") | |
143 | |
144 ;; 6) Add a product highlighting function. | |
145 | |
146 ;; (defun sql-highlight-xyz-keywords () | |
147 ;; "Highlight XyzDB keywords." | |
148 ;; (interactive) | |
149 ;; (sql-set-product 'xyz)) | |
150 | |
151 ;; 7) Add an autoloaded SQLi function. | |
152 | |
153 ;; ;;;###autoload | |
154 ;; (defun sql-xyz () | |
155 ;; "Run ixyz by XyzDB as an inferior process." | |
156 ;; (interactive) | |
157 ;; (sql-product-interactive 'xyz)) | |
158 | |
159 ;; 8) Add a connect function which formats the command line arguments | |
160 ;; and starts the product interpreter in a comint buffer. See the | |
161 ;; existing connect functions for examples of the types of | |
162 ;; processing available. | |
163 | |
164 ;; (defun sql-connect-xyz () | |
165 ;; "Create comint buffer and connect to XyzDB using the login | |
166 ;; parameters and command options." | |
167 ;; | |
168 ;; ;; Do something with `sql-user', `sql-password', | |
169 ;; ;; `sql-database', and `sql-server'. | |
170 ;; (let ((params sql-xyz-options)) | |
171 ;; (if (not (string= "" sql-server)) | |
172 ;; (setq params (append (list "-S" sql-server) params))) | |
173 ;; (if (not (string= "" sql-database)) | |
174 ;; (setq params (append (list "-D" sql-database) params))) | |
175 ;; (if (not (string= "" sql-password)) | |
176 ;; (setq params (append (list "-P" sql-password) params))) | |
177 ;; (if (not (string= "" sql-user)) | |
178 ;; (setq params (append (list "-U" sql-user) params))) | |
179 ;; (set-buffer (apply 'make-comint "SQL" sql-xyz-program | |
180 ;; nil params)))) | |
181 | |
182 ;; 9) Save and compile sql.el. | |
88 | 183 |
89 ;;; To Do: | 184 ;;; To Do: |
90 | 185 |
91 ;; Add better hilight support for other brands; there is a bias towards | 186 ;; Add better hilight support for other brands; there is a bias towards |
92 ;; Oracle because that's what I use at work. Anybody else just send in | 187 ;; Oracle because that's what I use at work. Anybody else just send in |
97 | 192 |
98 ;; Add different hilighting levels. | 193 ;; Add different hilighting levels. |
99 | 194 |
100 ;;; Thanks to all the people who helped me out: | 195 ;;; Thanks to all the people who helped me out: |
101 | 196 |
197 ;; Alex Schroeder <alex@gnu.org> | |
102 ;; Kai Blauberg <kai.blauberg@metla.fi> | 198 ;; Kai Blauberg <kai.blauberg@metla.fi> |
103 ;; <ibalaban@dalet.com> | 199 ;; <ibalaban@dalet.com> |
104 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il> | 200 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il> |
105 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> | 201 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> |
106 ;; nino <nino@inform.dk> | 202 ;; nino <nino@inform.dk> |
107 ;; Berend de Boer <berend@pobox.com> | 203 ;; Berend de Boer <berend@pobox.com> |
204 ;; Adam Jenkins <adam@thejenkins.org> | |
205 ;; Michael Mauger <mmaug@yahoo.com> -- improved product support | |
206 ;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support | |
207 ;; Harald Maier <maierh@myself.com> -- sql-send-string | |
208 ;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections | |
108 | 209 |
109 | 210 |
110 | 211 |
111 ;;; Code: | 212 ;;; Code: |
112 | 213 |
113 (require 'comint) | 214 (require 'comint) |
114 ;; Need the following to allow GNU Emacs 19 to compile the file. | 215 ;; Need the following to allow GNU Emacs 19 to compile the file. |
115 (require 'regexp-opt) | 216 (eval-when-compile |
217 (require 'regexp-opt)) | |
116 (require 'custom) | 218 (require 'custom) |
219 (eval-when-compile ;; needed in Emacs 19, 20 | |
220 (setq max-specpdl-size 2000)) | |
221 | |
222 (defvar font-lock-keyword-face) | |
223 (defvar font-lock-set-defaults) | |
224 (defvar font-lock-string-face) | |
117 | 225 |
118 ;;; Allow customization | 226 ;;; Allow customization |
119 | 227 |
120 (defgroup SQL nil | 228 (defgroup SQL nil |
121 "Running a SQL interpreter from within Emacs buffers" | 229 "Running a SQL interpreter from within Emacs buffers." |
122 :version "20.4" | 230 :version "20.4" |
123 :group 'processes) | 231 :group 'processes) |
124 | 232 |
125 ;; These three variables will be used as defaults, if set. | 233 ;; These four variables will be used as defaults, if set. |
126 | 234 |
127 (defcustom sql-user "" | 235 (defcustom sql-user "" |
128 "*Default username." | 236 "*Default username." |
129 :type 'string | 237 :type 'string |
130 :group 'SQL) | 238 :group 'SQL) |
144 | 252 |
145 (defcustom sql-server "" | 253 (defcustom sql-server "" |
146 "*Default server or host." | 254 "*Default server or host." |
147 :type 'string | 255 :type 'string |
148 :group 'SQL) | 256 :group 'SQL) |
257 | |
258 ;; SQL Product support | |
259 (defcustom sql-product 'ansi | |
260 "*Select the SQL database product used so that buffers can be | |
261 highlighted properly when you open them." | |
262 :type '(choice (const :tag "ANSI" ansi) | |
263 (const :tag "DB2" db2) | |
264 (const :tag "Informix" informix) | |
265 (const :tag "Ingres" ingres) | |
266 (const :tag "Interbase" interbase) | |
267 (const :tag "Linter" linter) | |
268 (const :tag "Microsoft" ms) | |
269 (const :tag "MySQL" mysql) | |
270 (const :tag "Oracle" oracle) | |
271 (const :tag "PostGres" postgres) | |
272 (const :tag "Solid" solid) | |
273 (const :tag "SQLite" sqlite) | |
274 (const :tag "Sybase" sybase)) | |
275 :group 'SQL) | |
276 | |
277 (defvar sql-interactive-product nil | |
278 "Product under `sql-interactive-mode'.") | |
279 | |
280 (defvar sql-product-alist | |
281 '((ansi | |
282 :font-lock sql-mode-ansi-font-lock-keywords) | |
283 (db2 | |
284 :font-lock sql-mode-db2-font-lock-keywords | |
285 :sqli-login nil | |
286 :sqli-connect sql-connect-db2 | |
287 :sqli-prompt-regexp "^db2 => " | |
288 :sqli-prompt-length 7) | |
289 (informix | |
290 :font-lock sql-mode-informix-font-lock-keywords | |
291 :sqli-login (database) | |
292 :sqli-connect sql-connect-informix | |
293 :sqli-prompt-regexp "^SQL> " | |
294 :sqli-prompt-length 5) | |
295 (ingres | |
296 :font-lock sql-mode-ingres-font-lock-keywords | |
297 :sqli-login (database) | |
298 :sqli-connect sql-connect-ingres | |
299 :sqli-prompt-regexp "^\* " | |
300 :sqli-prompt-length 2) | |
301 (interbase | |
302 :font-lock sql-mode-interbase-font-lock-keywords | |
303 :sqli-login (user password database) | |
304 :sqli-connect sql-connect-interbase | |
305 :sqli-prompt-regexp "^SQL> " | |
306 :sqli-prompt-length 5) | |
307 (linter | |
308 :font-lock sql-mode-linter-font-lock-keywords | |
309 :sqli-login (user password database server) | |
310 :sqli-connect sql-connect-linter | |
311 :sqli-prompt-regexp "^SQL>" | |
312 :sqli-prompt-length 4) | |
313 (ms | |
314 :font-lock sql-mode-ms-font-lock-keywords | |
315 :sqli-login (user password server database) | |
316 :sqli-connect sql-connect-ms | |
317 :sqli-prompt-regexp "^[0-9]*>" | |
318 :sqli-prompt-length 5 | |
319 :syntax-alist ((?@ . "w"))) | |
320 (mysql | |
321 :font-lock sql-mode-mysql-font-lock-keywords | |
322 :sqli-login (user password database server) | |
323 :sqli-connect sql-connect-mysql | |
324 :sqli-prompt-regexp "^mysql> " | |
325 :sqli-prompt-length 6) | |
326 (oracle | |
327 :font-lock sql-mode-oracle-font-lock-keywords | |
328 :sqli-login (user password database) | |
329 :sqli-connect sql-connect-oracle | |
330 :sqli-prompt-regexp "^SQL> " | |
331 :sqli-prompt-length 5 | |
332 :syntax-alist ((?$ . "w") (?# . "w"))) | |
333 (postgres | |
334 :font-lock sql-mode-postgres-font-lock-keywords | |
335 :sqli-login (user database server) | |
336 :sqli-connect sql-connect-postgres | |
337 :sqli-prompt-regexp "^.*[#>] *" | |
338 :sqli-prompt-length 5) | |
339 (solid | |
340 :font-lock sql-mode-solid-font-lock-keywords | |
341 :sqli-login (user password server) | |
342 :sqli-connect sql-connect-solid | |
343 :sqli-prompt-regexp "^" | |
344 :sqli-prompt-length 0) | |
345 (sqlite | |
346 :font-lock sql-mode-sqlite-font-lock-keywords | |
347 :sqli-login (user password server database) | |
348 :sqli-connect sql-connect-sqlite | |
349 :sqli-prompt-regexp "^sqlite> " | |
350 :sqli-prompt-length 8) | |
351 (sybase | |
352 :font-lock sql-mode-sybase-font-lock-keywords | |
353 :sqli-login (server user password database) | |
354 :sqli-connect sql-connect-sybase | |
355 :sqli-prompt-regexp "^SQL> " | |
356 :sqli-prompt-length 5 | |
357 :syntax-alist ((?@ . "w"))) | |
358 ) | |
359 "This variable contains a list of product features for each of the | |
360 SQL products handled by `sql-mode'. Without an entry in this list a | |
361 product will not be properly highlighted and will not support | |
362 `sql-interactive-mode'. | |
363 | |
364 Each element in the list is in the following format: | |
365 | |
366 \(PRODUCT FEATURE VALUE ...) | |
367 | |
368 where PRODUCT is the appropriate value of `sql-product'. The product | |
369 name is then followed by FEATURE-VALUE pairs. If a FEATURE is not | |
370 specified, its VALUE is treated as nil. FEATURE must be one of the | |
371 following: | |
372 | |
373 :font-lock name of the variable containing the product | |
374 specific font lock highlighting patterns. | |
375 | |
376 :sqli-login a list of login parameters (i.e., user, | |
377 password, database and server) needed to | |
378 connect to the database. | |
379 | |
380 :sqli-connect the name of a function which accepts no | |
381 parameters that will use the values of | |
382 `sql-user', `sql-password', | |
383 `sql-database' and `sql-server' to open a | |
384 comint buffer and connect to the | |
385 database. Do product specific | |
386 configuration of comint in this function. | |
387 | |
388 :sqli-prompt-regexp a regular expression string that matches | |
389 the prompt issued by the product | |
390 interpreter. (Not needed in 21.3+) | |
391 | |
392 :sqli-prompt-length the length of the prompt on the line.(Not | |
393 needed in 21.3+) | |
394 | |
395 :syntax-alist an alist of syntax table entries to enable | |
396 special character treatment by font-lock and | |
397 imenu. ") | |
149 | 398 |
150 ;; misc customization of sql.el behaviour | 399 ;; misc customization of sql.el behaviour |
151 | 400 |
152 (defcustom sql-electric-stuff nil | 401 (defcustom sql-electric-stuff nil |
153 "Treat some input as electric. | 402 "Treat some input as electric. |
175 :group 'SQL) | 424 :group 'SQL) |
176 | 425 |
177 ;; imenu support for sql-mode. | 426 ;; imenu support for sql-mode. |
178 | 427 |
179 (defvar sql-imenu-generic-expression | 428 (defvar sql-imenu-generic-expression |
180 '(("Tables" "^\\s-*create\\s-+table\\s-+\\(\\w+\\)" 1) | 429 ;; Items are in reverse order because they are rendered in reverse. |
181 ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1)) | 430 '(("Rules/Defaults" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(rule\\|default\\)\\s-+\\(\\w+\\)" 3) |
431 ("Sequences" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*sequence\\s-+\\(\\w+\\)" 2) | |
432 ("Triggers" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*trigger\\s-+\\(\\w+\\)" 2) | |
433 ("Functions" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?function\\s-+\\(\\w+\\)" 3) | |
434 ("Procedures" "^\\s-*\\(create\\s-+\\(\\w+\\s-+\\)*\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4) | |
435 ("Packages" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3) | |
436 ("Indexes" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*index\\s-+\\(\\w+\\)" 2) | |
437 ("Tables/Views" "^\\s-*create\\s-+\\(\\w+\\s-+\\)*\\(table\\|view\\)\\s-+\\(\\w+\\)" 3)) | |
182 "Define interesting points in the SQL buffer for `imenu'. | 438 "Define interesting points in the SQL buffer for `imenu'. |
183 | 439 |
184 This is used to set `imenu-generic-expression' when SQL mode is | 440 This is used to set `imenu-generic-expression' when SQL mode is |
185 entered. Subsequent changes to sql-imenu-generic-expression will not | 441 entered. Subsequent changes to sql-imenu-generic-expression will not |
186 affect existing SQL buffers because imenu-generic-expression is a | 442 affect existing SQL buffers because imenu-generic-expression is a |
260 "*List of additional options for `sql-oracle-program'." | 516 "*List of additional options for `sql-oracle-program'." |
261 :type '(repeat string) | 517 :type '(repeat string) |
262 :version "20.8" | 518 :version "20.8" |
263 :group 'SQL) | 519 :group 'SQL) |
264 | 520 |
521 ;; Customization for SQLite | |
522 | |
523 (defcustom sql-sqlite-program "sqlite" | |
524 "*Command to start SQLite. | |
525 | |
526 Starts `sql-interactive-mode' after doing some setup. | |
527 | |
528 The program can also specify a TCP connection. See `make-comint'." | |
529 :type 'file | |
530 :group 'SQL) | |
531 | |
532 (defcustom sql-sqlite-options nil | |
533 "*List of additional options for `sql-sqlite-program'. | |
534 The following list of options is reported to make things work | |
535 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"." | |
536 :type '(repeat string) | |
537 :version "20.8" | |
538 :group 'SQL) | |
539 | |
265 ;; Customization for MySql | 540 ;; Customization for MySql |
266 | 541 |
267 (defcustom sql-mysql-program "mysql" | 542 (defcustom sql-mysql-program "mysql" |
268 "*Command to start mysql by TcX. | 543 "*Command to start mysql by TcX. |
269 | 544 |
332 :type 'file | 607 :type 'file |
333 :group 'SQL) | 608 :group 'SQL) |
334 | 609 |
335 ;; Customization for Microsoft | 610 ;; Customization for Microsoft |
336 | 611 |
337 (defcustom sql-ms-program "isql" | 612 (defcustom sql-ms-program "osql" |
338 "*Command to start isql by Microsoft. | 613 "*Command to start osql by Microsoft. |
339 | 614 |
340 Starts `sql-interactive-mode' after doing some setup. | 615 Starts `sql-interactive-mode' after doing some setup. |
341 | 616 |
342 The program can also specify a TCP connection. See `make-comint'." | 617 The program can also specify a TCP connection. See `make-comint'." |
343 :type 'file | 618 :type 'file |
345 | 620 |
346 (defcustom sql-ms-options '("-w" "300" "-n") | 621 (defcustom sql-ms-options '("-w" "300" "-n") |
347 ;; -w is the linesize | 622 ;; -w is the linesize |
348 "*List of additional options for `sql-ms-program'." | 623 "*List of additional options for `sql-ms-program'." |
349 :type '(repeat string) | 624 :type '(repeat string) |
350 :version "21.4" | 625 :version "22.1" |
351 :group 'SQL) | 626 :group 'SQL) |
352 | 627 |
353 ;; Customization for Postgres | 628 ;; Customization for Postgres |
354 | 629 |
355 (defcustom sql-postgres-program "psql" | 630 (defcustom sql-postgres-program "psql" |
447 the local value of `sql-buffer' using \\[sql-set-sqli-buffer].") | 722 the local value of `sql-buffer' using \\[sql-set-sqli-buffer].") |
448 | 723 |
449 (defvar sql-prompt-regexp nil | 724 (defvar sql-prompt-regexp nil |
450 "Prompt used to initialize `comint-prompt-regexp'. | 725 "Prompt used to initialize `comint-prompt-regexp'. |
451 | 726 |
452 You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.") | 727 You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.") |
453 | 728 |
454 (defvar sql-prompt-length 0 | 729 (defvar sql-prompt-length 0 |
455 "Prompt used to set `left-margin' in `sql-interactive-mode'. | 730 "Prompt used to set `left-margin' in `sql-interactive-mode'. |
456 | 731 |
457 You can change it on `sql-interactive-mode-hook'.") | 732 You can change `sql-prompt-length' on `sql-interactive-mode-hook'.") |
458 | 733 |
459 (defvar sql-alternate-buffer-name nil | 734 (defvar sql-alternate-buffer-name nil |
460 "Buffer-local string used to possibly rename the SQLi buffer. | 735 "Buffer-local string used to possibly rename the SQLi buffer. |
461 | 736 |
462 Used by `sql-rename-buffer'.") | 737 Used by `sql-rename-buffer'.") |
463 | 738 |
464 ;; Keymap for sql-interactive-mode. | 739 ;; Keymap for sql-interactive-mode. |
465 | 740 |
466 (defvar sql-interactive-mode-map | 741 (defvar sql-interactive-mode-map |
467 (let ((map (make-sparse-keymap))) | 742 (let ((map (make-sparse-keymap))) |
468 (if (functionp 'set-keymap-parent) | 743 (if (fboundp 'set-keymap-parent) |
469 (set-keymap-parent map comint-mode-map); Emacs | 744 (set-keymap-parent map comint-mode-map); Emacs |
470 (set-keymap-parents map (list comint-mode-map))); XEmacs | 745 (if (fboundp 'set-keymap-parents) |
471 (if (functionp 'set-keymap-name) | 746 (set-keymap-parents map (list comint-mode-map)))); XEmacs |
747 (if (fboundp 'set-keymap-name) | |
472 (set-keymap-name map 'sql-interactive-mode-map)); XEmacs | 748 (set-keymap-name map 'sql-interactive-mode-map)); XEmacs |
473 (define-key map (kbd "C-j") 'sql-accumulate-and-indent) | 749 (define-key map (kbd "C-j") 'sql-accumulate-and-indent) |
474 (define-key map (kbd "C-c C-w") 'sql-copy-column) | 750 (define-key map (kbd "C-c C-w") 'sql-copy-column) |
475 (define-key map (kbd "O") 'sql-magic-go) | 751 (define-key map (kbd "O") 'sql-magic-go) |
476 (define-key map (kbd "o") 'sql-magic-go) | 752 (define-key map (kbd "o") 'sql-magic-go) |
483 | 759 |
484 (defvar sql-mode-map | 760 (defvar sql-mode-map |
485 (let ((map (make-sparse-keymap))) | 761 (let ((map (make-sparse-keymap))) |
486 (define-key map (kbd "C-c C-c") 'sql-send-paragraph) | 762 (define-key map (kbd "C-c C-c") 'sql-send-paragraph) |
487 (define-key map (kbd "C-c C-r") 'sql-send-region) | 763 (define-key map (kbd "C-c C-r") 'sql-send-region) |
764 (define-key map (kbd "C-c C-s") 'sql-send-string) | |
488 (define-key map (kbd "C-c C-b") 'sql-send-buffer) | 765 (define-key map (kbd "C-c C-b") 'sql-send-buffer) |
489 map) | 766 map) |
490 "Mode map used for `sql-mode'.") | 767 "Mode map used for `sql-mode'.") |
491 | 768 |
492 ;; easy menu for sql-mode. | 769 ;; easy menu for sql-mode. |
497 '("SQL" | 774 '("SQL" |
498 ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer) | 775 ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer) |
499 (get-buffer-process sql-buffer))] | 776 (get-buffer-process sql-buffer))] |
500 ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs | 777 ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs |
501 mark-active) | 778 mark-active) |
502 (mark)); XEmacs | 779 (mark t)); XEmacs |
503 (buffer-live-p sql-buffer) | 780 (buffer-live-p sql-buffer) |
504 (get-buffer-process sql-buffer))] | 781 (get-buffer-process sql-buffer))] |
505 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) | 782 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) |
506 (get-buffer-process sql-buffer))] | 783 (get-buffer-process sql-buffer))] |
784 ["Send String" sql-send-string t] | |
785 ["--" nil nil] | |
786 ["Start SQLi session" sql-product-interactive (sql-product-feature :sqli-connect)] | |
507 ["Show SQLi buffer" sql-show-sqli-buffer t] | 787 ["Show SQLi buffer" sql-show-sqli-buffer t] |
508 ["Set SQLi buffer" sql-set-sqli-buffer t] | 788 ["Set SQLi buffer" sql-set-sqli-buffer t] |
509 ["Pop to SQLi buffer after send" | 789 ["Pop to SQLi buffer after send" |
510 sql-toggle-pop-to-buffer-after-send-region | 790 sql-toggle-pop-to-buffer-after-send-region |
511 :style toggle | 791 :style toggle |
512 :selected sql-pop-to-buffer-after-send-region] | 792 :selected sql-pop-to-buffer-after-send-region] |
513 ("Highlighting" | 793 ["--" nil nil] |
514 ["ANSI SQL keywords" sql-highlight-ansi-keywords t] | 794 ("Product" |
515 ["Oracle keywords" sql-highlight-oracle-keywords t] | 795 ["ANSI" sql-highlight-ansi-keywords |
516 ["Postgres keywords" sql-highlight-postgres-keywords t] | 796 :style radio |
517 ["Linter keywords" sql-highlight-linter-keywords t] | 797 :selected (eq sql-product 'ansi)] |
798 ["DB2" sql-highlight-db2-keywords | |
799 :style radio | |
800 :selected (eq sql-product 'db2)] | |
801 ["Informix" sql-highlight-informix-keywords | |
802 :style radio | |
803 :selected (eq sql-product 'informix)] | |
804 ["Ingres" sql-highlight-ingres-keywords | |
805 :style radio | |
806 :selected (eq sql-product 'ingres)] | |
807 ["Interbase" sql-highlight-interbase-keywords | |
808 :style radio | |
809 :selected (eq sql-product 'interbase)] | |
810 ["Linter" sql-highlight-linter-keywords | |
811 :style radio | |
812 :selected (eq sql-product 'linter)] | |
813 ["MS SQLServer" sql-highlight-ms-keywords | |
814 :style radio | |
815 :selected (eq sql-product 'ms)] | |
816 ["MySQL" sql-highlight-mysql-keywords | |
817 :style radio | |
818 :selected (eq sql-product 'mysql)] | |
819 ["Oracle" sql-highlight-oracle-keywords | |
820 :style radio | |
821 :selected (eq sql-product 'oracle)] | |
822 ["Postgres" sql-highlight-postgres-keywords | |
823 :style radio | |
824 :selected (eq sql-product 'postgres)] | |
825 ["Solid" sql-highlight-solid-keywords | |
826 :style radio | |
827 :selected (eq sql-product 'solid)] | |
828 ["SQLite" sql-highlight-sqlite-keywords | |
829 :style radio | |
830 :selected (eq sql-product 'sqlite)] | |
831 ["Sybase" sql-highlight-sybase-keywords | |
832 :style radio | |
833 :selected (eq sql-product 'sybase)] | |
518 ))) | 834 ))) |
519 | 835 |
520 ;; easy menu for sql-interactive-mode. | 836 ;; easy menu for sql-interactive-mode. |
521 | 837 |
522 (easy-menu-define | 838 (easy-menu-define |
528 ;; Abbreviations -- if you want more of them, define them in your | 844 ;; Abbreviations -- if you want more of them, define them in your |
529 ;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too. | 845 ;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too. |
530 | 846 |
531 (defvar sql-mode-abbrev-table nil | 847 (defvar sql-mode-abbrev-table nil |
532 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.") | 848 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.") |
533 (if sql-mode-abbrev-table | 849 (unless sql-mode-abbrev-table |
534 () | 850 (define-abbrev-table 'sql-mode-abbrev-table nil) |
535 (let ((wrapper)) | 851 (mapcar |
536 (define-abbrev-table 'sql-mode-abbrev-table ()) | 852 ;; In Emacs 21.3+, provide SYSTEM-FLAG to define-abbrev. |
537 (define-abbrev sql-mode-abbrev-table "ins" "insert" nil 0 t) | 853 '(lambda (abbrev) |
538 (define-abbrev sql-mode-abbrev-table "upd" "update" nil 0 t) | 854 (let ((name (car abbrev)) |
539 (define-abbrev sql-mode-abbrev-table "del" "delete" nil 0 t) | 855 (expansion (cdr abbrev))) |
540 (define-abbrev sql-mode-abbrev-table "sel" "select" nil 0 t))) | 856 (condition-case nil |
857 (define-abbrev sql-mode-abbrev-table name expansion nil 0 t) | |
858 (error | |
859 (define-abbrev sql-mode-abbrev-table name expansion))))) | |
860 '(("ins" "insert") | |
861 ("upd" "update") | |
862 ("del" "delete") | |
863 ("sel" "select") | |
864 ("proc" "procedure") | |
865 ("func" "function") | |
866 ("cr" "create")))) | |
541 | 867 |
542 ;; Syntax Table | 868 ;; Syntax Table |
543 | 869 |
544 (defvar sql-mode-syntax-table | 870 (defvar sql-mode-syntax-table |
545 (let ((table (make-syntax-table))) | 871 (let ((table (make-syntax-table))) |
546 ;; C-style comments /**/ (see elisp manual "Syntax Flags")) | 872 ;; C-style comments /**/ (see elisp manual "Syntax Flags")) |
547 (modify-syntax-entry ?/ ". 14" table) | 873 (modify-syntax-entry ?/ ". 14" table) |
548 (modify-syntax-entry ?* ". 23" table) | 874 (modify-syntax-entry ?* ". 23" table) |
549 ;; double-dash starts comment | 875 ;; double-dash starts comment |
550 (if (string-match "XEmacs\\|Lucid" emacs-version) | 876 (modify-syntax-entry ?- ". 12b" table) |
551 (modify-syntax-entry ?- ". 56" table) | |
552 (modify-syntax-entry ?- ". 12b" table)) | |
553 ;; newline and formfeed end coments | 877 ;; newline and formfeed end coments |
554 (modify-syntax-entry ?\n "> b" table) | 878 (modify-syntax-entry ?\n "> b" table) |
555 (modify-syntax-entry ?\f "> b" table) | 879 (modify-syntax-entry ?\f "> b" table) |
556 ;; single quotes (') quotes delimit strings | 880 ;; single quotes (') quotes delimit strings |
557 (modify-syntax-entry ?' "\"" table) | 881 (modify-syntax-entry ?' "\"" table) |
560 table) | 884 table) |
561 "Syntax table used in `sql-mode' and `sql-interactive-mode'.") | 885 "Syntax table used in `sql-mode' and `sql-interactive-mode'.") |
562 | 886 |
563 ;; Font lock support | 887 ;; Font lock support |
564 | 888 |
565 (defvar sql-mode-ansi-font-lock-keywords nil | 889 (defvar sql-mode-font-lock-object-name |
890 (list (concat "^\\s-*\\(create\\|drop\\|alter\\)\\s-+" ;; lead off with CREATE, DROP or ALTER | |
891 "\\(\\w+\\s-+\\)*" ;; optional intervening keywords | |
892 "\\(table\\|view\\|package\\(\\s-+body\\)?\\|proc\\(edure\\)?" | |
893 "\\|function\\|trigger\\|sequence\\|rule\\|default\\)\\s-+" | |
894 "\\(\\w+\\)") | |
895 6 'font-lock-function-name-face) | |
896 | |
897 "Pattern to match the names of top-level objects. | |
898 | |
899 The pattern matches the name in a CREATE, DROP or ALTER | |
900 statement. The format of variable should be a valid | |
901 `font-lock-keywords' entry.") | |
902 | |
903 (defmacro sql-keywords-re (&rest keywords) | |
904 "Compile-time generation of regexp matching any one of KEYWORDS." | |
905 `(eval-when-compile | |
906 (concat "\\b" | |
907 (regexp-opt ',keywords t) | |
908 "\\b"))) | |
909 | |
910 (defvar sql-mode-ansi-font-lock-keywords | |
911 (let ((ansi-funcs (sql-keywords-re | |
912 "abs" "avg" "bit_length" "cardinality" "cast" "char_length" | |
913 "character_length" "coalesce" "convert" "count" "current_date" | |
914 "current_path" "current_role" "current_time" "current_timestamp" | |
915 "current_user" "extract" "localtime" "localtimestamp" "lower" "max" | |
916 "min" "mod" "nullif" "octet_length" "overlay" "placing" "session_user" | |
917 "substring" "sum" "system_user" "translate" "treat" "trim" "upper" | |
918 "user" | |
919 )) | |
920 | |
921 (ansi-non-reserved (sql-keywords-re | |
922 "ada" "asensitive" "assignment" "asymmetric" "atomic" "between" | |
923 "bitvar" "called" "catalog_name" "chain" "character_set_catalog" | |
924 "character_set_name" "character_set_schema" "checked" "class_origin" | |
925 "cobol" "collation_catalog" "collation_name" "collation_schema" | |
926 "column_name" "command_function" "command_function_code" "committed" | |
927 "condition_number" "connection_name" "constraint_catalog" | |
928 "constraint_name" "constraint_schema" "contains" "cursor_name" | |
929 "datetime_interval_code" "datetime_interval_precision" "defined" | |
930 "definer" "dispatch" "dynamic_function" "dynamic_function_code" | |
931 "existing" "exists" "final" "fortran" "generated" "granted" | |
932 "hierarchy" "hold" "implementation" "infix" "insensitive" "instance" | |
933 "instantiable" "invoker" "key_member" "key_type" "length" "m" | |
934 "message_length" "message_octet_length" "message_text" "method" "more" | |
935 "mumps" "name" "nullable" "number" "options" "overlaps" "overriding" | |
936 "parameter_mode" "parameter_name" "parameter_ordinal_position" | |
937 "parameter_specific_catalog" "parameter_specific_name" | |
938 "parameter_specific_schema" "pascal" "pli" "position" "repeatable" | |
939 "returned_length" "returned_octet_length" "returned_sqlstate" | |
940 "routine_catalog" "routine_name" "routine_schema" "row_count" "scale" | |
941 "schema_name" "security" "self" "sensitive" "serializable" | |
942 "server_name" "similar" "simple" "source" "specific_name" "style" | |
943 "subclass_origin" "sublist" "symmetric" "system" "table_name" | |
944 "transaction_active" "transactions_committed" | |
945 "transactions_rolled_back" "transform" "transforms" "trigger_catalog" | |
946 "trigger_name" "trigger_schema" "type" "uncommitted" "unnamed" | |
947 "user_defined_type_catalog" "user_defined_type_name" | |
948 "user_defined_type_schema" | |
949 )) | |
950 | |
951 (ansi-reserved (sql-keywords-re | |
952 "absolute" "action" "add" "admin" "after" "aggregate" "alias" "all" | |
953 "allocate" "alter" "and" "any" "are" "as" "asc" "assertion" "at" | |
954 "authorization" "before" "begin" "both" "breadth" "by" "call" | |
955 "cascade" "cascaded" "case" "catalog" "check" "class" "close" | |
956 "collate" "collation" "column" "commit" "completion" "connect" | |
957 "connection" "constraint" "constraints" "constructor" "continue" | |
958 "corresponding" "create" "cross" "cube" "current" "cursor" "cycle" | |
959 "data" "day" "deallocate" "declare" "default" "deferrable" "deferred" | |
960 "delete" "depth" "deref" "desc" "describe" "descriptor" "destroy" | |
961 "destructor" "deterministic" "diagnostics" "dictionary" "disconnect" | |
962 "distinct" "domain" "drop" "dynamic" "each" "else" "end" "equals" | |
963 "escape" "every" "except" "exception" "exec" "execute" "external" | |
964 "false" "fetch" "first" "for" "foreign" "found" "free" "from" "full" | |
965 "function" "general" "get" "global" "go" "goto" "grant" "group" | |
966 "grouping" "having" "host" "hour" "identity" "ignore" "immediate" "in" | |
967 "indicator" "initialize" "initially" "inner" "inout" "input" "insert" | |
968 "intersect" "into" "is" "isolation" "iterate" "join" "key" "language" | |
969 "last" "lateral" "leading" "left" "less" "level" "like" "limit" | |
970 "local" "locator" "map" "match" "minute" "modifies" "modify" "module" | |
971 "month" "names" "natural" "new" "next" "no" "none" "not" "null" "of" | |
972 "off" "old" "on" "only" "open" "operation" "option" "or" "order" | |
973 "ordinality" "out" "outer" "output" "pad" "parameter" "parameters" | |
974 "partial" "path" "postfix" "prefix" "preorder" "prepare" "preserve" | |
975 "primary" "prior" "privileges" "procedure" "public" "read" "reads" | |
976 "recursive" "references" "referencing" "relative" "restrict" "result" | |
977 "return" "returns" "revoke" "right" "role" "rollback" "rollup" | |
978 "routine" "rows" "savepoint" "schema" "scroll" "search" "second" | |
979 "section" "select" "sequence" "session" "set" "sets" "size" "some" | |
980 "space" "specific" "specifictype" "sql" "sqlexception" "sqlstate" | |
981 "sqlwarning" "start" "state" "statement" "static" "structure" "table" | |
982 "temporary" "terminate" "than" "then" "timezone_hour" | |
983 "timezone_minute" "to" "trailing" "transaction" "translation" | |
984 "trigger" "true" "under" "union" "unique" "unknown" "unnest" "update" | |
985 "usage" "using" "value" "values" "variable" "view" "when" "whenever" | |
986 "where" "with" "without" "work" "write" "year" | |
987 )) | |
988 | |
989 (ansi-types (sql-keywords-re | |
990 "array" "binary" "bit" "blob" "boolean" "char" "character" "clob" | |
991 "date" "dec" "decimal" "double" "float" "int" "integer" "interval" | |
992 "large" "national" "nchar" "nclob" "numeric" "object" "precision" | |
993 "real" "ref" "row" "scope" "smallint" "time" "timestamp" "varchar" | |
994 "varying" "zone" | |
995 ))) | |
996 | |
997 `((,ansi-non-reserved . font-lock-keyword-face) | |
998 (,ansi-reserved . font-lock-keyword-face) | |
999 (,ansi-funcs . font-lock-builtin-face) | |
1000 (,ansi-types . font-lock-type-face))) | |
1001 | |
566 "ANSI SQL keywords used by font-lock. | 1002 "ANSI SQL keywords used by font-lock. |
567 | 1003 |
568 This variable is used by `sql-mode' and `sql-interactive-mode'. The | 1004 This variable is used by `sql-mode' and `sql-interactive-mode'. The |
569 regular expressions are created during compilation by calling the | 1005 regular expressions are created during compilation by calling the |
570 function `regexp-opt'. Therefore, take a look at the source before | 1006 function `regexp-opt'. Therefore, take a look at the source before |
571 you define your own sql-mode-ansi-font-lock-keywords. You may want to | 1007 you define your own sql-mode-ansi-font-lock-keywords. You may want to |
572 add functions and PL/SQL keywords.") | 1008 add functions and PL/SQL keywords.") |
573 (if sql-mode-ansi-font-lock-keywords | 1009 |
574 () | 1010 (defvar sql-mode-oracle-font-lock-keywords |
575 (let ((ansi-keywords (eval-when-compile | 1011 (let ((oracle-functions (sql-keywords-re |
576 (concat "\\b" | 1012 "abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2" |
577 (regexp-opt '( | 1013 "avg" "bfilename" "bin_to_num" "bitand" "cast" "ceil" "chartorowid" |
578 "authorization" "avg" "begin" "close" "cobol" "commit" | 1014 "chr" "coalesce" "compose" "concat" "convert" "corr" "cos" "cosh" |
579 "continue" "count" "declare" "double" "end" "escape" | 1015 "count" "covar_pop" "covar_samp" "cume_dist" "current_date" |
580 "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator" | 1016 "current_timestamp" "current_user" "dbtimezone" "decode" "decompose" |
581 "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli" | 1017 "dense_rank" "depth" "deref" "dump" "empty_clob" "existsnode" "exp" |
582 "precision" "primary" "procedure" "references" "rollback" | 1018 "extract" "extractvalue" "first" "first_value" "floor" "following" |
583 "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work") t) "\\b"))) | 1019 "from_tz" "greatest" "group_id" "grouping_id" "hextoraw" "initcap" |
584 (ansi-reserved-words (eval-when-compile | 1020 "instr" "lag" "last" "last_day" "last_value" "lead" "least" "length" |
585 (concat "\\b" | 1021 "ln" "localtimestamp" "lower" "lpad" "ltrim" "make_ref" "max" "min" |
586 (regexp-opt '( | 1022 "mod" "months_between" "new_time" "next_day" "nls_charset_decl_len" |
587 "all" "and" "any" "as" "asc" "between" "by" "check" "create" | 1023 "nls_charset_id" "nls_charset_name" "nls_initcap" "nls_lower" |
588 "current" "default" "delete" "desc" "distinct" "exists" "float" "for" | 1024 "nls_upper" "nlssort" "ntile" "nullif" "numtodsinterval" |
589 "from" "grant" "group" "having" "in" "insert" "into" "is" | 1025 "numtoyminterval" "nvl" "nvl2" "over" "path" "percent_rank" |
590 "like" "not" "null" "of" "on" "option" "or" "order" "privileges" | 1026 "percentile_cont" "percentile_disc" "power" "preceding" "rank" |
591 "public" "select" "set" "table" "to" "union" "unique" | 1027 "ratio_to_report" "rawtohex" "rawtonhex" "reftohex" "regr_" |
592 "update" "user" "values" "view" "where" "with") t) "\\b"))) | 1028 "regr_avgx" "regr_avgy" "regr_count" "regr_intercept" "regr_r2" |
593 (ansi-types (eval-when-compile | 1029 "regr_slope" "regr_sxx" "regr_sxy" "regr_syy" "replace" "round" |
594 (concat "\\b" | 1030 "row_number" "rowidtochar" "rowidtonchar" "rpad" "rtrim" |
595 (regexp-opt '( | 1031 "sessiontimezone" "sign" "sin" "sinh" "soundex" "sqrt" "stddev" |
596 ;; ANSI Keywords that look like types | 1032 "stddev_pop" "stddev_samp" "substr" "sum" "sys_connect_by_path" |
597 "character" "cursor" "dec" "int" "real" | 1033 "sys_context" "sys_dburigen" "sys_extract_utc" "sys_guid" "sys_typeid" |
598 ;; ANSI Reserved Word that look like types | 1034 "sys_xmlagg" "sys_xmlgen" "sysdate" "systimestamp" "tan" "tanh" |
599 "char" "integer" "smallint" ) t) "\\b")))) | 1035 "to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte" |
600 (setq sql-mode-ansi-font-lock-keywords | 1036 "to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp" |
601 (list (cons ansi-keywords 'font-lock-function-name-face) | 1037 "to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc" |
602 (cons ansi-reserved-words 'font-lock-keyword-face) | 1038 "tz_offset" "uid" "unbounded" "unistr" "updatexml" "upper" "user" |
603 (cons ansi-types 'font-lock-type-face))))) | 1039 "userenv" "var_pop" "var_samp" "variance" "vsize" "width_bucket" "xml" |
604 | 1040 "xmlagg" "xmlattribute" "xmlcolattval" "xmlconcat" "xmlelement" |
605 (defvar sql-mode-oracle-font-lock-keywords nil | 1041 "xmlforest" "xmlsequence" "xmltransform" |
1042 )) | |
1043 | |
1044 (oracle-keywords (sql-keywords-re | |
1045 "abort" "access" "accessed" "account" "activate" "add" "admin" | |
1046 "advise" "after" "agent" "aggregate" "all" "allocate" "allow" "alter" | |
1047 "always" "analyze" "ancillary" "and" "any" "apply" "archive" | |
1048 "archivelog" "array" "as" "asc" "associate" "at" "attribute" | |
1049 "attributes" "audit" "authenticated" "authid" "authorization" "auto" | |
1050 "autoallocate" "automatic" "availability" "backup" "before" "begin" | |
1051 "behalf" "between" "binding" "bitmap" "block" "blocksize" "body" | |
1052 "both" "buffer_pool" "build" "by" "cache" "call" "cancel" | |
1053 "cascade" "case" "category" "certificate" "chained" "change" "check" | |
1054 "checkpoint" "child" "chunk" "class" "clear" "clone" "close" "cluster" | |
1055 "column" "column_value" "columns" "comment" "commit" "committed" | |
1056 "compatibility" "compile" "complete" "composite_limit" "compress" | |
1057 "compute" "connect" "connect_time" "consider" "consistent" | |
1058 "constraint" "constraints" "constructor" "contents" "context" | |
1059 "continue" "controlfile" "corruption" "cost" "cpu_per_call" | |
1060 "cpu_per_session" "create" "cross" "cube" "current" "currval" "cycle" | |
1061 "dangling" "data" "database" "datafile" "datafiles" "day" "ddl" | |
1062 "deallocate" "debug" "default" "deferrable" "deferred" "definer" | |
1063 "delay" "delete" "demand" "desc" "determines" "deterministic" | |
1064 "dictionary" "dimension" "directory" "disable" "disassociate" | |
1065 "disconnect" "distinct" "distinguished" "distributed" "dml" "drop" | |
1066 "each" "element" "else" "enable" "end" "equals_path" "escape" | |
1067 "estimate" "except" "exceptions" "exchange" "excluding" "exists" | |
1068 "expire" "explain" "extent" "external" "externally" | |
1069 "failed_login_attempts" "fast" "file" "final" "finish" "flush" "for" | |
1070 "force" "foreign" "freelist" "freelists" "freepools" "fresh" "from" | |
1071 "full" "function" "functions" "generated" "global" "global_name" | |
1072 "globally" "grant" "group" "grouping" "groups" "guard" "hash" | |
1073 "hashkeys" "having" "heap" "hierarchy" "id" "identified" "identifier" | |
1074 "idle_time" "immediate" "in" "including" "increment" "index" "indexed" | |
1075 "indexes" "indextype" "indextypes" "indicator" "initial" "initialized" | |
1076 "initially" "initrans" "inner" "insert" "instance" "instantiable" | |
1077 "instead" "intersect" "into" "invalidate" "is" "isolation" "java" | |
1078 "join" "keep" "key" "kill" "language" "left" "less" "level" | |
1079 "levels" "library" "like" "like2" "like4" "likec" "limit" "link" | |
1080 "list" "lob" "local" "location" "locator" "lock" "log" "logfile" | |
1081 "logging" "logical" "logical_reads_per_call" | |
1082 "logical_reads_per_session" "managed" "management" "manual" "map" | |
1083 "mapping" "master" "matched" "materialized" "maxdatafiles" | |
1084 "maxextents" "maximize" "maxinstances" "maxlogfiles" "maxloghistory" | |
1085 "maxlogmembers" "maxsize" "maxtrans" "maxvalue" "member" "memory" | |
1086 "merge" "migrate" "minextents" "minimize" "minimum" "minus" "minvalue" | |
1087 "mode" "modify" "monitoring" "month" "mount" "move" "movement" "name" | |
1088 "named" "natural" "nested" "never" "new" "next" "nextval" "no" | |
1089 "noarchivelog" "noaudit" "nocache" "nocompress" "nocopy" "nocycle" | |
1090 "nodelay" "noforce" "nologging" "nomapping" "nomaxvalue" "nominimize" | |
1091 "nominvalue" "nomonitoring" "none" "noorder" "noparallel" "norely" | |
1092 "noresetlogs" "noreverse" "normal" "norowdependencies" "nosort" | |
1093 "noswitch" "not" "nothing" "notimeout" "novalidate" "nowait" "null" | |
1094 "nulls" "object" "of" "off" "offline" "oidindex" "old" "on" "online" | |
1095 "only" "open" "operator" "optimal" "option" "or" "order" | |
1096 "organization" "out" "outer" "outline" "overflow" "overriding" | |
1097 "package" "packages" "parallel" "parallel_enable" "parameters" | |
1098 "parent" "partition" "partitions" "password" "password_grace_time" | |
1099 "password_life_time" "password_lock_time" "password_reuse_max" | |
1100 "password_reuse_time" "password_verify_function" "pctfree" | |
1101 "pctincrease" "pctthreshold" "pctused" "pctversion" "percent" | |
1102 "performance" "permanent" "pfile" "physical" "pipelined" "plan" | |
1103 "post_transaction" "pragma" "prebuilt" "preserve" "primary" "private" | |
1104 "private_sga" "privileges" "procedure" "profile" "protection" "public" | |
1105 "purge" "query" "quiesce" "quota" "range" "read" "reads" "rebuild" | |
1106 "records_per_block" "recover" "recovery" "recycle" "reduced" "ref" | |
1107 "references" "referencing" "refresh" "register" "reject" "relational" | |
1108 "rely" "rename" "reset" "resetlogs" "resize" "resolve" "resolver" | |
1109 "resource" "restrict" "restrict_references" "restricted" "result" | |
1110 "resumable" "resume" "retention" "return" "returning" "reuse" | |
1111 "reverse" "revoke" "rewrite" "right" "rnds" "rnps" "role" "roles" | |
1112 "rollback" "rollup" "row" "rowdependencies" "rownum" "rows" "sample" | |
1113 "savepoint" "scan" "schema" "scn" "scope" "segment" "select" | |
1114 "selectivity" "self" "sequence" "serializable" "session" | |
1115 "sessions_per_user" "set" "sets" "settings" "shared" "shared_pool" | |
1116 "shrink" "shutdown" "siblings" "sid" "single" "size" "skip" "some" | |
1117 "sort" "source" "space" "specification" "spfile" "split" "standby" | |
1118 "start" "statement_id" "static" "statistics" "stop" "storage" "store" | |
1119 "structure" "subpartition" "subpartitions" "substitutable" | |
1120 "successful" "supplemental" "suspend" "switch" "switchover" "synonym" | |
1121 "sys" "system" "table" "tables" "tablespace" "tempfile" "template" | |
1122 "temporary" "test" "than" "then" "thread" "through" "time_zone" | |
1123 "timeout" "to" "trace" "transaction" "trigger" "triggers" "truncate" | |
1124 "trust" "type" "types" "unarchived" "under" "under_path" "undo" | |
1125 "uniform" "union" "unique" "unlimited" "unlock" "unquiesce" | |
1126 "unrecoverable" "until" "unusable" "unused" "update" "upgrade" "usage" | |
1127 "use" "using" "validate" "validation" "value" "values" "variable" | |
1128 "varray" "version" "view" "wait" "when" "whenever" "where" "with" | |
1129 "without" "wnds" "wnps" "work" "write" "xmldata" "xmlschema" "xmltype" | |
1130 )) | |
1131 | |
1132 (oracle-types (sql-keywords-re | |
1133 "bfile" "blob" "byte" "char" "character" "clob" "date" "dec" "decimal" | |
1134 "double" "float" "int" "integer" "interval" "long" "national" "nchar" | |
1135 "nclob" "number" "numeric" "nvarchar2" "precision" "raw" "real" | |
1136 "rowid" "second" "smallint" "time" "timestamp" "urowid" "varchar" | |
1137 "varchar2" "varying" "year" "zone" | |
1138 )) | |
1139 | |
1140 (plsql-functions (sql-keywords-re | |
1141 "%bulk_rowcount" "%found" "%isopen" "%notfound" "%rowcount" "%rowtype" | |
1142 "%type" "extend" "prior" | |
1143 )) | |
1144 | |
1145 (plsql-keywords (sql-keywords-re | |
1146 "autonomous_transaction" "bulk" "char_base" "collect" "constant" | |
1147 "cursor" "declare" "do" "elsif" "exception_init" "execute" "exit" | |
1148 "extends" "false" "fetch" "forall" "goto" "hour" "if" "interface" | |
1149 "loop" "minute" "number_base" "ocirowid" "opaque" "others" "rowtype" | |
1150 "separate" "serially_reusable" "sql" "sqlcode" "sqlerrm" "subtype" | |
1151 "the" "timezone_abbr" "timezone_hour" "timezone_minute" | |
1152 "timezone_region" "true" "varrying" "while" | |
1153 )) | |
1154 | |
1155 (plsql-type (sql-keywords-re | |
1156 "binary_integer" "boolean" "naturaln" "pls_integer" "positive" | |
1157 "positiven" "record" "signtype" "string" | |
1158 )) | |
1159 | |
1160 (plsql-warning (sql-keywords-re | |
1161 "access_into_null" "case_not_found" "collection_is_null" | |
1162 "cursor_already_open" "dup_val_on_index" "invalid_cursor" | |
1163 "invalid_number" "login_denied" "no_data_found" "not_logged_on" | |
1164 "program_error" "rowtype_mismatch" "self_is_null" "storage_error" | |
1165 "subscript_beyond_count" "subscript_outside_limit" "sys_invalid_rowid" | |
1166 "timeout_on_resource" "too_many_rows" "value_error" "zero_divide" | |
1167 "exception" "notfound" | |
1168 )) | |
1169 | |
1170 (sqlplus-commands | |
1171 (eval-when-compile (concat "^\\(\\(" | |
1172 (regexp-opt '( | |
1173 "@" "@@" "accept" "append" "archive" "attribute" "break" | |
1174 "btitle" "change" "clear" "column" "connect" "copy" "define" | |
1175 "del" "describe" "disconnect" "edit" "execute" "exit" "get" "help" | |
1176 "host" "input" "list" "password" "pause" "print" "prompt" "recover" | |
1177 "remark" "repfooter" "repheader" "run" "save" "show" "shutdown" | |
1178 "spool" "start" "startup" "store" "timing" "ttitle" "undefine" | |
1179 "variable" "whenever" | |
1180 | |
1181 ) t) | |
1182 | |
1183 "\\)\\|" | |
1184 "\\(compute\\s-+\\(avg\\|cou\\|min\\|max\\|num\\|sum\\|std\\|var\\)\\)\\|" | |
1185 "\\(set\\s-+\\(appi\\(nfo\\)?\\|array\\(size\\)?\\|" | |
1186 "auto\\(commit\\)?\\|autop\\(rint\\)?\\|autorecovery\\|" | |
1187 "autot\\(race\\)?\\|blo\\(ckterminator\\)?\\|cmds\\(ep\\)?\\|" | |
1188 "colsep\\|com\\(patibility\\)?\\|con\\(cat\\)?\\|" | |
1189 "copyc\\(ommit\\)?\\|copytypecheck\\|def\\(ine\\)?\\|" | |
1190 "describe\\|echo\\|editf\\(ile\\)?\\|emb\\(edded\\)?\\|" | |
1191 "esc\\(ape\\)?\\|feed\\(back\\)?\\|flagger\\|" | |
1192 "flu\\(sh\\)?\\|hea\\(ding\\)?\\|heads\\(ep\\)?\\|" | |
1193 "instance\\|lin\\(esize\\)?\\|lobof\\(fset\\)?\\|" | |
1194 "logsource\\|long\\|longc\\(hunksize\\)?\\|mark\\(up\\)?\\|" | |
1195 "newp\\(age\\)?\\|null\\|numf\\(ormat\\)?\\|" | |
1196 "num\\(width\\)?\\|pages\\(ize\\)?\\|pau\\(se\\)?\\|" | |
1197 "recsep\\|recsepchar\\|serverout\\(put\\)?\\|" | |
1198 "shift\\(inout\\)?\\|show\\(mode\\)?\\|" | |
1199 "sqlbl\\(anklines\\)?\\|sqlc\\(ase\\)?\\|" | |
1200 "sqlco\\(ntinue\\)?\\|sqln\\(umber\\)?\\|" | |
1201 "sqlpluscompat\\(ibility\\)?\\|sqlpre\\(fix\\)?\\|" | |
1202 "sqlp\\(rompt\\)?\\|sqlt\\(erminator\\)?\\|" | |
1203 "suf\\(fix\\)?\\|tab\\|term\\(out\\)?\\|ti\\(me\\)?\\|" | |
1204 "timi\\(ng\\)?\\|trim\\(out\\)?\\|trims\\(pool\\)?\\|" | |
1205 "und\\(erline\\)?\\|ver\\(ify\\)?\\|wra\\(p\\)?\\)\\)\\)" | |
1206 "\\b.*$" | |
1207 )))) | |
1208 | |
1209 `((,sqlplus-commands . font-lock-doc-face) | |
1210 (,oracle-functions . font-lock-builtin-face) | |
1211 (,oracle-keywords . font-lock-keyword-face) | |
1212 (,oracle-types . font-lock-type-face) | |
1213 (,plsql-functions . font-lock-builtin-face) | |
1214 (,plsql-keywords . font-lock-keyword-face) | |
1215 (,plsql-type . font-lock-type-face) | |
1216 (,plsql-warning . font-lock-warning-face))) | |
1217 | |
606 "Oracle SQL keywords used by font-lock. | 1218 "Oracle SQL keywords used by font-lock. |
607 | 1219 |
608 This variable is used by `sql-mode' and `sql-interactive-mode'. The | 1220 This variable is used by `sql-mode' and `sql-interactive-mode'. The |
609 regular expressions are created during compilation by calling the | 1221 regular expressions are created during compilation by calling the |
610 function `regexp-opt'. Therefore, take a look at the source before | 1222 function `regexp-opt'. Therefore, take a look at the source before |
611 you define your own sql-mode-oracle-font-lock-keywords. You may want | 1223 you define your own sql-mode-oracle-font-lock-keywords. You may want |
612 to add functions and PL/SQL keywords.") | 1224 to add functions and PL/SQL keywords.") |
613 (if sql-mode-oracle-font-lock-keywords | 1225 |
614 () | 1226 (defvar sql-mode-postgres-font-lock-keywords |
615 (let ((oracle-keywords (eval-when-compile | 1227 (let ((pg-funcs (sql-keywords-re |
616 (concat "\\b" | 1228 "abbrev" "abs" "acos" "age" "area" "ascii" "asin" "atab2" "atan" |
617 (regexp-opt '( | 1229 "atan2" "avg" "bit_length" "both" "broadcast" "btrim" "cbrt" "ceil" |
618 "admin" "after" "allocate" "analyze" "archive" "archivelog" "backup" | 1230 "center" "char_length" "chr" "coalesce" "col_description" "convert" |
619 "become" "before" "block" "body" "cache" "cancel" "cascade" "change" | 1231 "cos" "cot" "count" "current_database" "current_date" "current_schema" |
620 "checkpoint" "compile" "constraint" "constraints" "contents" | 1232 "current_schemas" "current_setting" "current_time" "current_timestamp" |
621 "controlfile" "cycle" "database" "datafile" "dba" "disable" "dismount" | 1233 "current_user" "currval" "date_part" "date_trunc" "decode" "degrees" |
622 "dump" "each" "else" "elsif" "enable" "events" "except" "exceptions" | 1234 "diameter" "encode" "exp" "extract" "floor" "get_bit" "get_byte" |
623 "execute" "exit" "explain" "extent" "externally" "false" "flush" "force" | 1235 "has_database_privilege" "has_function_privilege" |
624 "freelist" "freelists" "function" "groups" "if" "including" "initrans" | 1236 "has_language_privilege" "has_schema_privilege" "has_table_privilege" |
625 "instance" "layer" "link" "lists" "logfile" "loop" "manage" "manual" | 1237 "height" "host" "initcap" "isclosed" "isfinite" "isopen" "leading" |
626 "maxdatafiles" "maxinistances" "maxlogfiles" "maxloghistory" | 1238 "length" "ln" "localtime" "localtimestamp" "log" "lower" "lpad" |
627 "maxlogmembers" "maxtrans" "maxvalue" "minextents" "minvalue" "mount" | 1239 "ltrim" "masklen" "max" "min" "mod" "netmask" "network" "nextval" |
628 "new" "next" "noarchivelog" "nocache" "nocycle" "nomaxvalue" | 1240 "now" "npoints" "nullif" "obj_description" "octet_length" "overlay" |
629 "nominvalue" "none" "noorder" "noresetlogs" "normal" "nosort" "off" | 1241 "pclose" "pg_client_encoding" "pg_function_is_visible" |
630 "old" "only" "optimal" "others" "out" "own" "package" "parallel" | 1242 "pg_get_constraintdef" "pg_get_indexdef" "pg_get_ruledef" |
631 "pctincrease" "pctused" "plan" "pragma" "private" "profile" "quota" | 1243 "pg_get_userbyid" "pg_get_viewdef" "pg_opclass_is_visible" |
632 "raise" "read" "recover" "referencing" "resetlogs" "restrict_references" | 1244 "pg_operator_is_visible" "pg_table_is_visible" "pg_type_is_visible" |
633 "restricted" "return" "returning" "reuse" "rnds" "rnps" "role" "roles" | 1245 "pi" "popen" "position" "pow" "quote_ident" "quote_literal" "radians" |
634 "savepoint" "scn" "segment" "sequence" "shared" "snapshot" "sort" | 1246 "radius" "random" "repeat" "replace" "round" "rpad" "rtrim" |
635 "statement_id" "statistics" "stop" "storage" "subtype" "switch" "system" | 1247 "session_user" "set_bit" "set_byte" "set_config" "set_masklen" |
636 "tables" "tablespace" "temporary" "thread" "time" "tracing" | 1248 "setval" "sign" "sin" "split_part" "sqrt" "stddev" "strpos" "substr" |
637 "transaction" "triggers" "true" "truncate" "type" "under" "unlimited" | 1249 "substring" "sum" "tan" "timeofday" "to_ascii" "to_char" "to_date" |
638 "until" "use" "using" "when" "while" "wnds" "wnps" "write") t) "\\b"))) | 1250 "to_hex" "to_number" "to_timestamp" "trailing" "translate" "trim" |
639 (oracle-warning-words (eval-when-compile | 1251 "trunc" "upper" "variance" "version" "width" |
640 (concat "\\b" | 1252 )) |
641 (regexp-opt '( | 1253 |
642 "cursor_already_open" "dup_val_on_index" "exception" "invalid_cursor" | 1254 (pg-reserved (sql-keywords-re |
643 "invalid_number" "login_denied" "no_data_found" "not_logged_on" | 1255 "abort" "access" "add" "after" "aggregate" "alignment" "all" "alter" |
644 "notfound" "others" "pragma" "program_error" "storage_error" | 1256 "analyze" "and" "any" "as" "asc" "assignment" "authorization" |
645 "timeout_on_resource" "too_many_rows" "transaction_backed_out" | 1257 "backward" "basetype" "before" "begin" "between" "binary" "by" "cache" |
646 "value_error" "zero_divide") t) "\\b"))) | 1258 "called" "cascade" "case" "cast" "characteristics" "check" |
647 (oracle-reserved-words (eval-when-compile | 1259 "checkpoint" "class" "close" "cluster" "column" "comment" "commit" |
648 (concat "\\b" | 1260 "committed" "commutator" "constraint" "constraints" "conversion" |
649 (regexp-opt '( | 1261 "copy" "create" "createdb" "createuser" "cursor" "cycle" "database" |
650 "access" "add" "alter" "audit" "cluster" "column" "comment" "compress" | 1262 "deallocate" "declare" "default" "deferrable" "deferred" "definer" |
651 "connect" "drop" "else" "exclusive" "file" "grant" | 1263 "delete" "delimiter" "desc" "distinct" "do" "domain" "drop" "each" |
652 "identified" "immediate" "increment" "index" "initial" "intersect" | 1264 "element" "else" "encoding" "encrypted" "end" "escape" "except" |
653 "level" "lock" "long" "maxextents" "minus" "mode" "modify" "noaudit" | 1265 "exclusive" "execute" "exists" "explain" "extended" "external" "false" |
654 "nocompress" "nowait" "number" "offline" "online" "pctfree" "prior" | 1266 "fetch" "finalfunc" "for" "force" "foreign" "forward" "freeze" "from" |
655 "raw" "rename" "resource" "revoke" "row" "rowlabel" "rownum" | 1267 "full" "function" "grant" "group" "gtcmp" "handler" "hashes" "having" |
656 "rows" "session" "share" "size" "start" "successful" "synonym" "sysdate" | 1268 "immediate" "immutable" "implicit" "in" "increment" "index" "inherits" |
657 "then" "trigger" "uid" "validate" "whenever") t) "\\b"))) | 1269 "initcond" "initially" "input" "insensitive" "insert" "instead" |
658 (oracle-types (eval-when-compile | 1270 "internallength" "intersect" "into" "invoker" "is" "isnull" |
659 (concat "\\b" | 1271 "isolation" "join" "key" "language" "leftarg" "level" "like" "limit" |
660 (regexp-opt '( | 1272 "listen" "load" "local" "location" "lock" "ltcmp" "main" "match" |
661 ;; Oracle Keywords that look like types | 1273 "maxvalue" "merges" "minvalue" "mode" "move" "natural" "negator" |
662 ;; Oracle Reserved Words that look like types | 1274 "next" "nocreatedb" "nocreateuser" "none" "not" "nothing" "notify" |
663 "binary_integer" "blob" "boolean" "constant" "date" "decimal" "rowid" | 1275 "notnull" "null" "of" "offset" "oids" "on" "only" "operator" "or" |
664 "varchar" "varchar2") t) "\\b"))) | 1276 "order" "output" "owner" "partial" "passedbyvalue" "password" "plain" |
665 (oracle-builtin-functions (eval-when-compile | 1277 "prepare" "primary" "prior" "privileges" "procedural" "procedure" |
666 (concat "\\b" | 1278 "public" "read" "recheck" "references" "reindex" "relative" "rename" |
667 (regexp-opt '( | 1279 "reset" "restrict" "returns" "revoke" "rightarg" "rollback" "row" |
668 ;; Misc Oracle builtin functions | 1280 "rule" "schema" "scroll" "security" "select" "sequence" "serializable" |
669 "abs" "add_months" "ascii" "avg" "ceil" "chartorowid" "chr" "concat" | 1281 "session" "set" "sfunc" "share" "show" "similar" "some" "sort1" |
670 "convert" "cos" "cosh" "count" "currval" "decode" "dump" "exp" "floor" | 1282 "sort2" "stable" "start" "statement" "statistics" "storage" "strict" |
671 "glb" "greatest" "greatest_lb" "hextoraw" "initcap" "instr" "instrb" | 1283 "stype" "sysid" "table" "temp" "template" "temporary" "then" "to" |
672 "last_day" "least" "least_ub" "length" "lengthb" "ln" "log" "lower" | 1284 "transaction" "trigger" "true" "truncate" "trusted" "type" |
673 "lpad" "ltrim" "lub" "max" "min" "mod" "months_between" "new_time" | 1285 "unencrypted" "union" "unique" "unknown" "unlisten" "until" "update" |
674 "next_day" "nextval" "nls_initcap" "nls_lower" "nls_upper" "nlssort" | 1286 "usage" "user" "using" "vacuum" "valid" "validator" "values" |
675 "nvl" "power" "rawtohex" "replace" "round" "rowidtochar" "rpad" | 1287 "variable" "verbose" "view" "volatile" "when" "where" "with" "without" |
676 "rtrim" "sign" "sin" "sinh" "soundex" "sqlcode" "sqlerrm" "sqrt" | 1288 "work" |
677 "stddev" "sum" "substr" "substrb" "tan" "tanh" "to_char" | 1289 )) |
678 "to_date" "to_label" "to_multi_byte" "to_number" "to_single_byte" | 1290 |
679 "translate" "trim" "trunc" "uid" "upper" "userenv" "variance" "vsize") t) "\\b")))) | 1291 (pg-types (sql-keywords-re |
680 (setq sql-mode-oracle-font-lock-keywords | 1292 "anyarray" "bigint" "bigserial" "bit" "boolean" "box" "bytea" "char" |
681 (append sql-mode-ansi-font-lock-keywords | 1293 "character" "cidr" "circle" "cstring" "date" "decimal" "double" |
682 (list (cons oracle-keywords 'font-lock-function-name-face) | 1294 "float4" "float8" "inet" "int2" "int4" "int8" "integer" "internal" |
683 (cons oracle-warning-words 'font-lock-warning-face) | 1295 "interval" "language_handler" "line" "lseg" "macaddr" "money" |
684 (cons oracle-reserved-words 'font-lock-keyword-face) | 1296 "numeric" "oid" "opaque" "path" "point" "polygon" "precision" "real" |
685 ;; XEmacs doesn't have font-lock-builtin-face | 1297 "record" "regclass" "regoper" "regoperator" "regproc" "regprocedure" |
686 (if (string-match "XEmacs\\|Lucid" emacs-version) | 1298 "regtype" "serial" "serial4" "serial8" "smallint" "text" "time" |
687 (cons oracle-builtin-functions 'font-lock-preprocessor-face) | 1299 "timestamp" "varchar" "varying" "void" "zone" |
688 ;; GNU Emacs 19 doesn't have it either | 1300 ))) |
689 (if (string-match "GNU Emacs 19" emacs-version) | 1301 |
690 (cons oracle-builtin-functions 'font-lock-function-name-face) | 1302 `((,pg-funcs . font-lock-builtin-face) |
691 ;; Emacs | 1303 (,pg-reserved . font-lock-keyword-face) |
692 (cons oracle-builtin-functions 'font-lock-builtin-face))) | 1304 (,pg-types . font-lock-type-face))) |
693 (cons oracle-types 'font-lock-type-face)))))) | 1305 |
694 | |
695 (defvar sql-mode-postgres-font-lock-keywords nil | |
696 "Postgres SQL keywords used by font-lock. | 1306 "Postgres SQL keywords used by font-lock. |
697 | 1307 |
698 This variable is used by `sql-mode' and `sql-interactive-mode'. The | 1308 This variable is used by `sql-mode' and `sql-interactive-mode'. The |
699 regular expressions are created during compilation by calling the | 1309 regular expressions are created during compilation by calling the |
700 function `regexp-opt'. Therefore, take a look at the source before | 1310 function `regexp-opt'. Therefore, take a look at the source before |
701 you define your own sql-mode-postgres-font-lock-keywords.") | 1311 you define your own sql-mode-postgres-font-lock-keywords.") |
702 | 1312 |
703 (if sql-mode-postgres-font-lock-keywords | 1313 (defvar sql-mode-linter-font-lock-keywords |
704 () | 1314 (let ((linter-keywords (sql-keywords-re |
705 (let ((postgres-reserved-words (eval-when-compile | |
706 (concat "\\b" | |
707 (regexp-opt '( | |
708 "language" | |
709 ) t) "\\b"))) | |
710 (postgres-types (eval-when-compile | |
711 (concat "\\b" | |
712 (regexp-opt '( | |
713 "bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date" | |
714 "float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path" | |
715 "point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar" | |
716 ) t)"\\b"))) | |
717 (postgres-builtin-functions (eval-when-compile | |
718 (concat "\\b" | |
719 (regexp-opt '( | |
720 ;; Misc Postgres builtin functions | |
721 "abstime" "age" "area" "box" "center" "date_part" "date_trunc" | |
722 "datetime" "dexp" "diameter" "dpow" "float" "float4" "height" | |
723 "initcap" "integer" "isclosed" "isfinite" "isoldpath" "isopen" | |
724 "length" "lower" "lpad" "ltrim" "pclose" "point" "points" "popen" | |
725 "position" "radius" "reltime" "revertpoly" "rpad" "rtrim" "substr" | |
726 "substring" "text" "timespan" "translate" "trim" "upgradepath" | |
727 "upgradepoly" "upper" "varchar" "width" | |
728 ) t) "\\b")))) | |
729 (setq sql-mode-postgres-font-lock-keywords | |
730 (append sql-mode-ansi-font-lock-keywords | |
731 (list (cons postgres-reserved-words 'font-lock-keyword-face) | |
732 ;; XEmacs doesn't have 'font-lock-builtin-face | |
733 (if (string-match "XEmacs\\|Lucid" emacs-version) | |
734 (cons postgres-builtin-functions 'font-lock-preprocessor-face) | |
735 ;; Emacs | |
736 (cons postgres-builtin-functions 'font-lock-builtin-face)) | |
737 (cons postgres-types 'font-lock-type-face)))))) | |
738 | |
739 | |
740 (defvar sql-mode-linter-font-lock-keywords nil | |
741 "Linter SQL keywords used by font-lock. | |
742 | |
743 This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
744 regular expressions are created during compilation by calling the | |
745 function `regexp-opt'.") | |
746 | |
747 (if sql-mode-linter-font-lock-keywords | |
748 () | |
749 (let ((linter-keywords (eval-when-compile | |
750 (concat "\\b" | |
751 (regexp-opt '( | |
752 "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel" | 1315 "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel" |
753 "committed" "count" "countblob" "cross" "current" "data" "database" | 1316 "committed" "count" "countblob" "cross" "current" "data" "database" |
754 "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred" | 1317 "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred" |
755 "denied" "description" "device" "difference" "directory" "error" | 1318 "denied" "description" "device" "difference" "directory" "error" |
756 "escape" "euc" "exclusive" "external" "extfile" "false" "file" | 1319 "escape" "euc" "exclusive" "external" "extfile" "false" "file" |
771 "startup" "statement" "station" "success" "sys_guid" "tables" "test" | 1334 "startup" "statement" "station" "success" "sys_guid" "tables" "test" |
772 "timeout" "trace" "transaction" "translation" "trigger" | 1335 "timeout" "trace" "transaction" "translation" "trigger" |
773 "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown" | 1336 "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown" |
774 "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes" | 1337 "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes" |
775 "wait" "windows_code" "workspace" "write" "xml" | 1338 "wait" "windows_code" "workspace" "write" "xml" |
776 ) t) "\\b"))) | 1339 )) |
777 (linter-reserved-words (eval-when-compile | 1340 |
778 (concat "\\b" | 1341 (linter-reserved (sql-keywords-re |
779 (regexp-opt '( | |
780 "access" "action" "add" "address" "after" "all" "alter" "always" "and" | 1342 "access" "action" "add" "address" "after" "all" "alter" "always" "and" |
781 "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit" | 1343 "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit" |
782 "aud_obj_name_len" "backup" "base" "before" "between" "blobfile" | 1344 "aud_obj_name_len" "backup" "base" "before" "between" "blobfile" |
783 "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check" | 1345 "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check" |
784 "clear" "close" "column" "comment" "commit" "connect" "contains" | 1346 "clear" "close" "column" "comment" "commit" "connect" "contains" |
792 "purge" "rebuild" "resource" "restrict" "revoke" "right" "role" | 1354 "purge" "rebuild" "resource" "restrict" "revoke" "right" "role" |
793 "rollback" "rownum" "select" "session" "set" "share" "shutdown" | 1355 "rollback" "rownum" "select" "session" "set" "share" "shutdown" |
794 "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then" | 1356 "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then" |
795 "to" "union" "unique" "unlock" "until" "update" "using" "values" | 1357 "to" "union" "unique" "unlock" "until" "update" "using" "values" |
796 "view" "when" "where" "with" "without" | 1358 "view" "when" "where" "with" "without" |
797 ) t) "\\b"))) | 1359 )) |
798 (linter-types (eval-when-compile | 1360 |
799 (concat "\\b" | 1361 (linter-types (sql-keywords-re |
800 (regexp-opt '( | |
801 "bigint" "bitmap" "blob" "boolean" "char" "character" "date" | 1362 "bigint" "bitmap" "blob" "boolean" "char" "character" "date" |
802 "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar" | 1363 "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar" |
803 "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte" | 1364 "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte" |
804 "cursor" "long" | 1365 "cursor" "long" |
805 ) t) "\\b"))) | 1366 )) |
806 (linter-builtin-functions (eval-when-compile | 1367 |
807 (concat "\\b" | 1368 (linter-functions (sql-keywords-re |
808 (regexp-opt '( | |
809 "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime" | 1369 "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime" |
810 "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw" | 1370 "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw" |
811 "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log" | 1371 "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log" |
812 "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl" | 1372 "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl" |
813 "octet_length" "power" "rand" "rawtohex" "repeat_string" | 1373 "octet_length" "power" "rand" "rawtohex" "repeat_string" |
814 "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex" | 1374 "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex" |
815 "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date" | 1375 "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date" |
816 "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode" | 1376 "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode" |
817 "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap" | 1377 "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap" |
818 "instr" "least" "multime" "replace" "width" | 1378 "instr" "least" "multime" "replace" "width" |
819 ) t) "\\b")))) | 1379 ))) |
820 (setq sql-mode-linter-font-lock-keywords | 1380 |
821 (append sql-mode-ansi-font-lock-keywords | 1381 `((,linter-keywords . font-lock-keyword-face) |
822 (list (cons linter-keywords 'font-lock-function-name-face) | 1382 (,linter-reserved . font-lock-keyword-face) |
823 (cons linter-reserved-words 'font-lock-keyword-face) | 1383 (,linter-functions . font-lock-builtin-face) |
824 ;; XEmacs doesn't have font-lock-builtin-face | 1384 (,linter-types . font-lock-type-face))) |
825 (if (string-match "XEmacs\\|Lucid" emacs-version) | 1385 |
826 (cons linter-builtin-functions 'font-lock-preprocessor-face) | 1386 "Linter SQL keywords used by font-lock. |
827 ;; GNU Emacs 19 doesn't have it either | 1387 |
828 (if (string-match "GNU Emacs 19" emacs-version) | 1388 This variable is used by `sql-mode' and `sql-interactive-mode'. The |
829 (cons linter-builtin-functions 'font-lock-function-name-face) | 1389 regular expressions are created during compilation by calling the |
830 ;; Emacs | 1390 function `regexp-opt'.") |
831 (cons linter-builtin-functions 'font-lock-builtin-face))) | 1391 |
832 (cons linter-types 'font-lock-type-face)))))) | 1392 (defvar sql-mode-ms-font-lock-keywords |
833 | 1393 (let ((ms-reserved (sql-keywords-re |
834 (defvar sql-mode-font-lock-keywords sql-mode-ansi-font-lock-keywords | 1394 "absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization" |
1395 "avg" "backup" "begin" "between" "break" "browse" "bulk" "by" | |
1396 "cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce" | |
1397 "column" "commit" "committed" "compute" "confirm" "constraint" | |
1398 "contains" "containstable" "continue" "controlrow" "convert" "count" | |
1399 "create" "cross" "current" "current_date" "current_time" | |
1400 "current_timestamp" "current_user" "database" "deallocate" "declare" | |
1401 "default" "delete" "deny" "desc" "disk" "distinct" "distributed" | |
1402 "double" "drop" "dummy" "dump" "else" "end" "errlvl" "errorexit" | |
1403 "escape" "except" "exec" "execute" "exists" "exit" "fetch" "file" | |
1404 "fillfactor" "first" "floppy" "for" "foreign" "freetext" | |
1405 "freetexttable" "from" "full" "goto" "grant" "group" "having" | |
1406 "holdlock" "identity" "identity_insert" "identitycol" "if" "in" | |
1407 "index" "inner" "insert" "intersect" "into" "is" "isolation" "join" | |
1408 "key" "kill" "last" "left" "level" "like" "lineno" "load" "max" "min" | |
1409 "mirrorexit" "national" "next" "nocheck" "nolock" "nonclustered" "not" | |
1410 "null" "nullif" "of" "off" "offsets" "on" "once" "only" "open" | |
1411 "opendatasource" "openquery" "openrowset" "option" "or" "order" | |
1412 "outer" "output" "over" "paglock" "percent" "perm" "permanent" "pipe" | |
1413 "plan" "precision" "prepare" "primary" "print" "prior" "privileges" | |
1414 "proc" "procedure" "processexit" "public" "raiserror" "read" | |
1415 "readcommitted" "readpast" "readtext" "readuncommitted" "reconfigure" | |
1416 "references" "relative" "repeatable" "repeatableread" "replication" | |
1417 "restore" "restrict" "return" "revoke" "right" "rollback" "rowcount" | |
1418 "rowguidcol" "rowlock" "rule" "save" "schema" "select" "serializable" | |
1419 "session_user" "set" "shutdown" "some" "statistics" "sum" | |
1420 "system_user" "table" "tablock" "tablockx" "tape" "temp" "temporary" | |
1421 "textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate" | |
1422 "tsequal" "uncommitted" "union" "unique" "update" "updatetext" | |
1423 "updlock" "use" "user" "values" "view" "waitfor" "when" "where" | |
1424 "while" "with" "work" "writetext" "collate" "function" "openxml" | |
1425 "returns" | |
1426 )) | |
1427 | |
1428 (ms-types (sql-keywords-re | |
1429 "binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal" | |
1430 "double" "float" "image" "int" "integer" "money" "national" "nchar" | |
1431 "ntext" "numeric" "numeric" "nvarchar" "precision" "real" | |
1432 "smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint" | |
1433 "uniqueidentifier" "varbinary" "varchar" "varying" | |
1434 )) | |
1435 | |
1436 (ms-vars "\\b@[a-zA-Z0-9_]*\\b") | |
1437 | |
1438 (ms-functions (sql-keywords-re | |
1439 "@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts" | |
1440 "@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy" | |
1441 "@@langid" "@@language" "@@lock_timeout" "@@max_connections" | |
1442 "@@max_precision" "@@nestlevel" "@@options" "@@pack_received" | |
1443 "@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount" | |
1444 "@@servername" "@@servicename" "@@spid" "@@textsize" "@@timeticks" | |
1445 "@@total_errors" "@@total_read" "@@total_write" "@@trancount" | |
1446 "@@version" "abs" "acos" "and" "app_name" "ascii" "asin" "atan" "atn2" | |
1447 "avg" "case" "cast" "ceiling" "char" "charindex" "coalesce" | |
1448 "col_length" "col_name" "columnproperty" "containstable" "convert" | |
1449 "cos" "cot" "count" "current_timestamp" "current_user" "cursor_status" | |
1450 "databaseproperty" "datalength" "dateadd" "datediff" "datename" | |
1451 "datepart" "day" "db_id" "db_name" "degrees" "difference" "exp" | |
1452 "file_id" "file_name" "filegroup_id" "filegroup_name" | |
1453 "filegroupproperty" "fileproperty" "floor" "formatmessage" | |
1454 "freetexttable" "fulltextcatalogproperty" "fulltextserviceproperty" | |
1455 "getansinull" "getdate" "grouping" "host_id" "host_name" "ident_incr" | |
1456 "ident_seed" "identity" "index_col" "indexproperty" "is_member" | |
1457 "is_srvrolemember" "isdate" "isnull" "isnumeric" "left" "len" "log" | |
1458 "log10" "lower" "ltrim" "max" "min" "month" "nchar" "newid" "nullif" | |
1459 "object_id" "object_name" "objectproperty" "openquery" "openrowset" | |
1460 "parsename" "patindex" "patindex" "permissions" "pi" "power" | |
1461 "quotename" "radians" "rand" "replace" "replicate" "reverse" "right" | |
1462 "round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt" | |
1463 "square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum" | |
1464 "suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan" | |
1465 "textptr" "textvalid" "typeproperty" "unicode" "upper" "user" | |
1466 "user_id" "user_name" "var" "varp" "year" | |
1467 )) | |
1468 | |
1469 (ms-commands | |
1470 (eval-when-compile | |
1471 (concat "^\\(\\(set\\s-+\\(" | |
1472 (regexp-opt '( | |
1473 "datefirst" "dateformat" "deadlock_priority" "lock_timeout" | |
1474 "concat_null_yields_null" "cursor_close_on_commit" | |
1475 "disable_def_cnst_chk" "fips_flagger" "identity_insert" "language" | |
1476 "offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly" | |
1477 "nocount" "noexec" "numeric_roundabort" "parseonly" | |
1478 "query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults" | |
1479 "ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding" | |
1480 "ansi_warnings" "forceplan" "showplan_all" "showplan_text" | |
1481 "statistics" "implicit_transactions" "remote_proc_transactions" | |
1482 "transaction" "xact_abort" | |
1483 ) t) | |
1484 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$")))) | |
1485 | |
1486 `((,ms-commands . font-lock-doc-face) | |
1487 (,ms-reserved . font-lock-keyword-face) | |
1488 (,ms-functions . font-lock-builtin-face) | |
1489 (,ms-vars . font-lock-variable-name-face) | |
1490 (,ms-types . font-lock-type-face))) | |
1491 | |
1492 "Microsoft SQLServer SQL keywords used by font-lock. | |
1493 | |
1494 This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1495 regular expressions are created during compilation by calling the | |
1496 function `regexp-opt'. Therefore, take a look at the source before | |
1497 you define your own sql-mode-ms-font-lock-keywords.") | |
1498 | |
1499 (defvar sql-mode-sybase-font-lock-keywords nil | |
1500 "Sybase SQL keywords used by font-lock. | |
1501 | |
1502 This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1503 regular expressions are created during compilation by calling the | |
1504 function `regexp-opt'. Therefore, take a look at the source before | |
1505 you define your own sql-mode-sybase-font-lock-keywords.") | |
1506 | |
1507 (defvar sql-mode-informix-font-lock-keywords nil | |
1508 "Informix SQL keywords used by font-lock. | |
1509 | |
1510 This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1511 regular expressions are created during compilation by calling the | |
1512 function `regexp-opt'. Therefore, take a look at the source before | |
1513 you define your own sql-mode-informix-font-lock-keywords.") | |
1514 | |
1515 (defvar sql-mode-interbase-font-lock-keywords nil | |
1516 "Interbase SQL keywords used by font-lock. | |
1517 | |
1518 This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1519 regular expressions are created during compilation by calling the | |
1520 function `regexp-opt'. Therefore, take a look at the source before | |
1521 you define your own sql-mode-interbase-font-lock-keywords.") | |
1522 | |
1523 (defvar sql-mode-ingres-font-lock-keywords nil | |
1524 "Ingres SQL keywords used by font-lock. | |
1525 | |
1526 This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1527 regular expressions are created during compilation by calling the | |
1528 function `regexp-opt'. Therefore, take a look at the source before | |
1529 you define your own sql-mode-interbase-font-lock-keywords.") | |
1530 | |
1531 (defvar sql-mode-solid-font-lock-keywords nil | |
1532 "Solid SQL keywords used by font-lock. | |
1533 | |
1534 This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1535 regular expressions are created during compilation by calling the | |
1536 function `regexp-opt'. Therefore, take a look at the source before | |
1537 you define your own sql-mode-solid-font-lock-keywords.") | |
1538 | |
1539 (defvar sql-mode-mysql-font-lock-keywords | |
1540 (let ((mysql-funcs (sql-keywords-re | |
1541 "ascii" "avg" "bdmpolyfromtext" "bdmpolyfromwkb" "bdpolyfromtext" | |
1542 "bdpolyfromwkb" "benchmark" "bin" "bit_and" "bit_length" "bit_or" | |
1543 "bit_xor" "both" "cast" "char_length" "character_length" "coalesce" | |
1544 "concat" "concat_ws" "connection_id" "conv" "convert" "count" | |
1545 "curdate" "current_date" "current_time" "current_timestamp" "curtime" | |
1546 "elt" "encrypt" "export_set" "field" "find_in_set" "found_rows" "from" | |
1547 "geomcollfromtext" "geomcollfromwkb" "geometrycollectionfromtext" | |
1548 "geometrycollectionfromwkb" "geometryfromtext" "geometryfromwkb" | |
1549 "geomfromtext" "geomfromwkb" "get_lock" "group_concat" "hex" "ifnull" | |
1550 "instr" "interval" "isnull" "last_insert_id" "lcase" "leading" | |
1551 "length" "linefromtext" "linefromwkb" "linestringfromtext" | |
1552 "linestringfromwkb" "load_file" "locate" "lower" "lpad" "ltrim" | |
1553 "make_set" "master_pos_wait" "max" "mid" "min" "mlinefromtext" | |
1554 "mlinefromwkb" "mpointfromtext" "mpointfromwkb" "mpolyfromtext" | |
1555 "mpolyfromwkb" "multilinestringfromtext" "multilinestringfromwkb" | |
1556 "multipointfromtext" "multipointfromwkb" "multipolygonfromtext" | |
1557 "multipolygonfromwkb" "now" "nullif" "oct" "octet_length" "ord" | |
1558 "pointfromtext" "pointfromwkb" "polyfromtext" "polyfromwkb" | |
1559 "polygonfromtext" "polygonfromwkb" "position" "quote" "rand" | |
1560 "release_lock" "repeat" "replace" "reverse" "rpad" "rtrim" "soundex" | |
1561 "space" "std" "stddev" "substring" "substring_index" "sum" "sysdate" | |
1562 "trailing" "trim" "ucase" "unix_timestamp" "upper" "user" "variance" | |
1563 )) | |
1564 | |
1565 (mysql-keywords (sql-keywords-re | |
1566 "action" "add" "after" "against" "all" "alter" "and" "as" "asc" | |
1567 "auto_increment" "avg_row_length" "bdb" "between" "by" "cascade" | |
1568 "case" "change" "character" "check" "checksum" "close" "collate" | |
1569 "collation" "column" "columns" "comment" "committed" "concurrent" | |
1570 "constraint" "create" "cross" "data" "database" "default" | |
1571 "delay_key_write" "delayed" "delete" "desc" "directory" "disable" | |
1572 "distinct" "distinctrow" "do" "drop" "dumpfile" "duplicate" "else" | |
1573 "enable" "enclosed" "end" "escaped" "exists" "fields" "first" "for" | |
1574 "force" "foreign" "from" "full" "fulltext" "global" "group" "handler" | |
1575 "having" "heap" "high_priority" "if" "ignore" "in" "index" "infile" | |
1576 "inner" "insert" "insert_method" "into" "is" "isam" "isolation" "join" | |
1577 "key" "keys" "last" "left" "level" "like" "limit" "lines" "load" | |
1578 "local" "lock" "low_priority" "match" "max_rows" "merge" "min_rows" | |
1579 "mode" "modify" "mrg_myisam" "myisam" "natural" "next" "no" "not" | |
1580 "null" "offset" "oj" "on" "open" "optionally" "or" "order" "outer" | |
1581 "outfile" "pack_keys" "partial" "password" "prev" "primary" | |
1582 "procedure" "quick" "raid0" "raid_type" "read" "references" "rename" | |
1583 "repeatable" "restrict" "right" "rollback" "rollup" "row_format" | |
1584 "savepoint" "select" "separator" "serializable" "session" "set" | |
1585 "share" "show" "sql_big_result" "sql_buffer_result" "sql_cache" | |
1586 "sql_calc_found_rows" "sql_no_cache" "sql_small_result" "starting" | |
1587 "straight_join" "striped" "table" "tables" "temporary" "terminated" | |
1588 "then" "to" "transaction" "truncate" "type" "uncommitted" "union" | |
1589 "unique" "unlock" "update" "use" "using" "values" "when" "where" | |
1590 "with" "write" "xor" | |
1591 )) | |
1592 | |
1593 (mysql-types (sql-keywords-re | |
1594 "bigint" "binary" "bit" "blob" "bool" "boolean" "char" "curve" "date" | |
1595 "datetime" "dec" "decimal" "double" "enum" "fixed" "float" "geometry" | |
1596 "geometrycollection" "int" "integer" "line" "linearring" "linestring" | |
1597 "longblob" "longtext" "mediumblob" "mediumint" "mediumtext" | |
1598 "multicurve" "multilinestring" "multipoint" "multipolygon" | |
1599 "multisurface" "national" "numeric" "point" "polygon" "precision" | |
1600 "real" "smallint" "surface" "text" "time" "timestamp" "tinyblob" | |
1601 "tinyint" "tinytext" "unsigned" "varchar" "year" "year2" "year4" | |
1602 "zerofill" | |
1603 ))) | |
1604 | |
1605 `((,mysql-funcs . font-lock-builtin-face) | |
1606 (,mysql-keywords . font-lock-keyword-face) | |
1607 (,mysql-types . font-lock-type-face))) | |
1608 | |
1609 "MySQL SQL keywords used by font-lock. | |
1610 | |
1611 This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1612 regular expressions are created during compilation by calling the | |
1613 function `regexp-opt'. Therefore, take a look at the source before | |
1614 you define your own sql-mode-mysql-font-lock-keywords.") | |
1615 | |
1616 (defvar sql-mode-sqlite-font-lock-keywords nil | |
1617 "SQLite SQL keywords used by font-lock. | |
1618 | |
1619 This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1620 regular expressions are created during compilation by calling the | |
1621 function `regexp-opt'. Therefore, take a look at the source before | |
1622 you define your own sql-mode-sqlite-font-lock-keywords.") | |
1623 | |
1624 (defvar sql-mode-db2-font-lock-keywords nil | |
1625 "DB2 SQL keywords used by font-lock. | |
1626 | |
1627 This variable is used by `sql-mode' and `sql-interactive-mode'. The | |
1628 regular expressions are created during compilation by calling the | |
1629 function `regexp-opt'. Therefore, take a look at the source before | |
1630 you define your own sql-mode-db2-font-lock-keywords.") | |
1631 | |
1632 (defvar sql-mode-font-lock-keywords nil | |
835 "SQL keywords used by font-lock. | 1633 "SQL keywords used by font-lock. |
836 | 1634 |
837 This variable defaults to `sql-mode-ansi-font-lock-keywords'. This is | 1635 Setting this variable directly no longer has any affect. Use |
838 used for the default `font-lock-defaults' value in `sql-mode'. This | 1636 `sql-product' and `sql-add-product-keywords' to control the |
839 can be changed by some entry functions to provide more hilighting.") | 1637 highlighting rules in sql-mode.") |
840 | 1638 |
841 | 1639 |
842 | 1640 |
1641 ;;; SQL Product support functions | |
1642 | |
1643 (defun sql-product-feature (feature &optional product) | |
1644 "Lookup `feature' needed to support the current SQL product. | |
1645 | |
1646 See \[sql-product-alist] for a list of products and supported features." | |
1647 (plist-get | |
1648 (cdr (assoc (or product sql-product) | |
1649 sql-product-alist)) | |
1650 feature)) | |
1651 | |
1652 (defun sql-product-font-lock (keywords-only imenu) | |
1653 "Sets `font-lock-defaults' and `font-lock-keywords' based on | |
1654 the product-specific keywords and syntax-alists defined in | |
1655 `sql-product-alist'." | |
1656 (let | |
1657 ;; Get the product-specific syntax-alist. | |
1658 ((syntax-alist | |
1659 (append | |
1660 (sql-product-feature :syntax-alist) | |
1661 '((?_ . "w") (?. . "w"))))) | |
1662 | |
1663 ;; Get the product-specific keywords. | |
1664 (setq sql-mode-font-lock-keywords | |
1665 (append | |
1666 (unless (eq sql-product 'ansi) | |
1667 (eval (sql-product-feature :font-lock))) | |
1668 ;; Always highlight ANSI keywords | |
1669 (eval (sql-product-feature :font-lock 'ansi)) | |
1670 ;; Fontify object names in CREATE, DROP and ALTER DDL | |
1671 ;; statements | |
1672 (list sql-mode-font-lock-object-name))) | |
1673 | |
1674 ;; Setup font-lock. Force re-parsing of `font-lock-defaults'. | |
1675 (set (make-local-variable 'font-lock-set-defaults) nil) | |
1676 (setq font-lock-defaults (list 'sql-mode-font-lock-keywords | |
1677 keywords-only t syntax-alist)) | |
1678 | |
1679 ;; Force font lock to reinitialize if it is already on | |
1680 ;; Otherwise, we can wait until it can be started. | |
1681 (when (and (fboundp 'font-lock-mode) | |
1682 font-lock-mode) | |
1683 (font-lock-mode-internal nil) | |
1684 (font-lock-mode-internal t)) | |
1685 | |
1686 (add-hook 'font-lock-mode-hook | |
1687 (lambda () | |
1688 ;; Provide defaults for new font-lock faces. | |
1689 (defvar font-lock-builtin-face | |
1690 (if (boundp 'font-lock-preprocessor-face) | |
1691 font-lock-preprocessor-face | |
1692 font-lock-keyword-face)) | |
1693 (defvar font-lock-doc-face font-lock-string-face)) | |
1694 nil t) | |
1695 | |
1696 ;; Setup imenu; it needs the same syntax-alist. | |
1697 (when imenu | |
1698 (setq imenu-syntax-alist syntax-alist)))) | |
1699 | |
1700 ;;;###autoload | |
1701 (defun sql-add-product-keywords (product keywords &optional append) | |
1702 "Add highlighting KEYWORDS for SQL PRODUCT. | |
1703 | |
1704 PRODUCT should be a symbol, the name of a sql product, such as | |
1705 `oracle'. KEYWORDS should be a list; see the variable | |
1706 `font-lock-keywords'. By default they are added at the beginning | |
1707 of the current highlighting list. If optional argument APPEND is | |
1708 `set', they are used to replace the current highlighting list. | |
1709 If APPEND is any other non-nil value, they are added at the end | |
1710 of the current highlighting list. | |
1711 | |
1712 For example: | |
1713 | |
1714 (sql-add-product-keywords 'ms | |
1715 '((\"\\\\b\\\\w+_t\\\\b\" . font-lock-type-face))) | |
1716 | |
1717 adds a fontification pattern to fontify identifiers ending in | |
1718 `_t' as data types." | |
1719 | |
1720 (let ((font-lock (sql-product-feature :font-lock product)) | |
1721 old) | |
1722 (setq old (eval font-lock)) | |
1723 (set font-lock | |
1724 (if (eq append 'set) | |
1725 keywords | |
1726 (if append | |
1727 (append old keywords) | |
1728 (append keywords old)))))) | |
1729 | |
1730 | |
1731 | |
843 ;;; Functions to switch highlighting | 1732 ;;; Functions to switch highlighting |
844 | 1733 |
1734 (defun sql-highlight-product () | |
1735 "Turns on the appropriate font highlighting for the SQL product | |
1736 selected." | |
1737 | |
1738 (when (eq major-mode 'sql-mode) | |
1739 ;; Setup font-lock | |
1740 (sql-product-font-lock nil t) | |
1741 | |
1742 ;; Set the mode name to include the product. | |
1743 (setq mode-name (concat "SQL[" (prin1-to-string sql-product) "]")))) | |
1744 | |
1745 (defun sql-set-product (product) | |
1746 "Set `sql-product' to product and enable appropriate | |
1747 highlighting." | |
1748 (interactive "SEnter SQL product: ") | |
1749 (when (not (assoc product sql-product-alist)) | |
1750 (error "SQL product %s is not supported; treated as ANSI" product) | |
1751 (setq product 'ansi)) | |
1752 | |
1753 ;; Save product setting and fontify. | |
1754 (setq sql-product product) | |
1755 (sql-highlight-product)) | |
1756 | |
845 (defun sql-highlight-oracle-keywords () | 1757 (defun sql-highlight-oracle-keywords () |
846 "Highlight Oracle keywords. | 1758 "Highlight Oracle keywords." |
847 Basically, this just sets `font-lock-keywords' appropriately." | 1759 (interactive) |
848 (interactive) | 1760 (sql-set-product 'oracle)) |
849 (setq font-lock-keywords sql-mode-oracle-font-lock-keywords) | |
850 (font-lock-fontify-buffer)) | |
851 | 1761 |
852 (defun sql-highlight-postgres-keywords () | 1762 (defun sql-highlight-postgres-keywords () |
853 "Highlight Postgres keywords. | 1763 "Highlight Postgres keywords." |
854 Basically, this just sets `font-lock-keywords' appropriately." | 1764 (interactive) |
855 (interactive) | 1765 (sql-set-product 'postgres)) |
856 (setq font-lock-keywords sql-mode-postgres-font-lock-keywords) | |
857 (font-lock-fontify-buffer)) | |
858 | 1766 |
859 (defun sql-highlight-linter-keywords () | 1767 (defun sql-highlight-linter-keywords () |
860 "Highlight LINTER keywords. | 1768 "Highlight LINTER keywords." |
861 Basically, this just sets `font-lock-keywords' appropriately." | 1769 (interactive) |
862 (interactive) | 1770 (sql-set-product 'linter)) |
863 (setq font-lock-keywords sql-mode-linter-font-lock-keywords) | 1771 |
864 (font-lock-fontify-buffer)) | 1772 (defun sql-highlight-ms-keywords () |
1773 "Highlight Microsoft SQLServer keywords." | |
1774 (interactive) | |
1775 (sql-set-product 'ms)) | |
865 | 1776 |
866 (defun sql-highlight-ansi-keywords () | 1777 (defun sql-highlight-ansi-keywords () |
867 "Highlight ANSI SQL keywords. | 1778 "Highlight ANSI SQL keywords." |
868 Basically, this just sets `font-lock-keywords' appropriately." | 1779 (interactive) |
869 (interactive) | 1780 (sql-set-product 'ansi)) |
870 (setq font-lock-keywords sql-mode-ansi-font-lock-keywords) | 1781 |
871 (font-lock-fontify-buffer)) | 1782 (defun sql-highlight-sybase-keywords () |
1783 "Highlight Sybase SQL keywords." | |
1784 (interactive) | |
1785 (sql-set-product 'sybase)) | |
1786 | |
1787 (defun sql-highlight-informix-keywords () | |
1788 "Highlight Informix SQL keywords." | |
1789 (interactive) | |
1790 (sql-set-product 'informix)) | |
1791 | |
1792 (defun sql-highlight-interbase-keywords () | |
1793 "Highlight Interbase SQL keywords." | |
1794 (interactive) | |
1795 (sql-set-product 'interbase)) | |
1796 | |
1797 (defun sql-highlight-ingres-keywords () | |
1798 "Highlight Ingres SQL keywords." | |
1799 (interactive) | |
1800 (sql-set-product 'ingres)) | |
1801 | |
1802 (defun sql-highlight-solid-keywords () | |
1803 "Highlight Solid SQL keywords." | |
1804 (interactive) | |
1805 (sql-set-product 'solid)) | |
1806 | |
1807 (defun sql-highlight-mysql-keywords () | |
1808 "Highlight MySQL SQL keywords." | |
1809 (interactive) | |
1810 (sql-set-product 'mysql)) | |
1811 | |
1812 (defun sql-highlight-sqlite-keywords () | |
1813 "Highlight SQLite SQL keywords." | |
1814 (interactive) | |
1815 (sql-set-product 'sqlite)) | |
1816 | |
1817 (defun sql-highlight-db2-keywords () | |
1818 "Highlight DB2 SQL keywords." | |
1819 (interactive) | |
1820 (sql-set-product 'db2)) | |
872 | 1821 |
873 | 1822 |
874 | 1823 |
875 ;;; Compatibility functions | 1824 ;;; Compatibility functions |
876 | 1825 |
922 | 1871 |
923 Use the following commands to start a specific SQL interpreter: | 1872 Use the following commands to start a specific SQL interpreter: |
924 | 1873 |
925 PostGres: \\[sql-postgres] | 1874 PostGres: \\[sql-postgres] |
926 MySQL: \\[sql-mysql] | 1875 MySQL: \\[sql-mysql] |
1876 SQLite: \\[sql-sqlite] | |
927 | 1877 |
928 Other non-free SQL implementations are also supported: | 1878 Other non-free SQL implementations are also supported: |
929 | 1879 |
930 Solid: \\[sql-solid] | 1880 Solid: \\[sql-solid] |
931 Oracle: \\[sql-oracle] | 1881 Oracle: \\[sql-oracle] |
932 Informix: \\[sql-informix] | 1882 Informix: \\[sql-informix] |
933 Sybase: \\[sql-sybase] | 1883 Sybase: \\[sql-sybase] |
934 Ingres: \\[sql-ingres] | 1884 Ingres: \\[sql-ingres] |
935 Microsoft: \\[sql-ms] | 1885 Microsoft: \\[sql-ms] |
1886 DB2: \\[sql-db2] | |
936 Interbase: \\[sql-interbase] | 1887 Interbase: \\[sql-interbase] |
937 Linter: \\[sql-linter] | 1888 Linter: \\[sql-linter] |
938 | 1889 |
939 But we urge you to choose a free implementation instead of these. | 1890 But we urge you to choose a free implementation instead of these. |
940 | 1891 |
953 appended to the SQLi buffer without disturbing your SQL buffer." | 1904 appended to the SQLi buffer without disturbing your SQL buffer." |
954 (interactive) | 1905 (interactive) |
955 (describe-function 'sql-help)) | 1906 (describe-function 'sql-help)) |
956 | 1907 |
957 (defun sql-read-passwd (prompt &optional default) | 1908 (defun sql-read-passwd (prompt &optional default) |
958 "Read a password using PROMPT. | 1909 "Read a password using PROMPT. Optional DEFAULT is password to start with." |
959 Optional DEFAULT is password to start with. This function calls | 1910 (read-passwd prompt nil default)) |
960 `read-passwd' if it is available. If not, function | |
961 `ange-ftp-read-passwd' is called. This should always be available, | |
962 even in old versions of Emacs." | |
963 (if (fboundp 'read-passwd) | |
964 (read-passwd prompt nil default) | |
965 (unless (fboundp 'ange-ftp-read-passwd) | |
966 (autoload 'ange-ftp-read-passwd "ange-ftp")) | |
967 (ange-ftp-read-passwd prompt default))) | |
968 | 1911 |
969 (defun sql-get-login (&rest what) | 1912 (defun sql-get-login (&rest what) |
970 "Get username, password and database from the user. | 1913 "Get username, password and database from the user. |
971 | 1914 |
972 The variables `sql-user', `sql-password', `sql-server', and | 1915 The variables `sql-user', `sql-password', `sql-server', and |
977 | 1920 |
978 Parameter WHAT is a list of the arguments passed to this function. | 1921 Parameter WHAT is a list of the arguments passed to this function. |
979 The function asks for the username if WHAT contains symbol `user', for | 1922 The function asks for the username if WHAT contains symbol `user', for |
980 the password if it contains symbol `password', for the server if it | 1923 the password if it contains symbol `password', for the server if it |
981 contains symbol `server', and for the database if it contains symbol | 1924 contains symbol `server', and for the database if it contains symbol |
982 `database'. | 1925 `database'. The members of WHAT are processed in the order in which |
1926 they are provided. | |
983 | 1927 |
984 In order to ask the user for username, password and database, call the | 1928 In order to ask the user for username, password and database, call the |
985 function like this: (sql-get-login 'user 'password 'database)." | 1929 function like this: (sql-get-login 'user 'password 'database)." |
986 (interactive) | 1930 (interactive) |
987 (if (memq 'user what) | 1931 (while what |
1932 (cond | |
1933 ((eq (car what) 'user) ; user | |
988 (setq sql-user | 1934 (setq sql-user |
989 (read-from-minibuffer "User: " sql-user nil nil | 1935 (read-from-minibuffer "User: " sql-user nil nil |
990 sql-user-history))) | 1936 sql-user-history))) |
991 (if (memq 'password what) | 1937 ((eq (car what) 'password) ; password |
992 (setq sql-password | 1938 (setq sql-password |
993 (sql-read-passwd "Password: " sql-password))) | 1939 (sql-read-passwd "Password: " sql-password))) |
994 (if (memq 'server what) | 1940 ((eq (car what) 'server) ; server |
995 (setq sql-server | 1941 (setq sql-server |
996 (read-from-minibuffer "Server: " sql-server nil nil | 1942 (read-from-minibuffer "Server: " sql-server nil nil |
997 sql-server-history))) | 1943 sql-server-history))) |
998 (if (memq 'database what) | 1944 ((eq (car what) 'database) ; database |
999 (setq sql-database | 1945 (setq sql-database |
1000 (read-from-minibuffer "Database: " sql-database nil nil | 1946 (read-from-minibuffer "Database: " sql-database nil nil |
1001 sql-database-history)))) | 1947 sql-database-history)))) |
1948 (setq what (cdr what)))) | |
1002 | 1949 |
1003 (defun sql-find-sqli-buffer () | 1950 (defun sql-find-sqli-buffer () |
1004 "Return the current default SQLi buffer or nil. | 1951 "Return the current default SQLi buffer or nil. |
1005 In order to qualify, the SQLi buffer must be alive, | 1952 In order to qualify, the SQLi buffer must be alive, |
1006 be in `sql-interactive-mode' and have a process." | 1953 be in `sql-interactive-mode' and have a process." |
1126 (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+" | 2073 (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+" |
1127 bol t)) | 2074 bol t)) |
1128 (insert ", ")) | 2075 (insert ", ")) |
1129 ;; else insert a space | 2076 ;; else insert a space |
1130 (t | 2077 (t |
1131 (if (eq (preceding-char) ? ) | 2078 (if (eq (preceding-char) ?\s) |
1132 nil | 2079 nil |
1133 (insert " "))))) | 2080 (insert " "))))) |
1134 ;; in any case, insert the column | 2081 ;; in any case, insert the column |
1135 (insert column) | 2082 (insert column) |
1136 (message "%s" column)))) | 2083 (message "%s" column)))) |
1213 (defun sql-send-buffer () | 2160 (defun sql-send-buffer () |
1214 "Send the buffer contents to the SQL process." | 2161 "Send the buffer contents to the SQL process." |
1215 (interactive) | 2162 (interactive) |
1216 (sql-send-region (point-min) (point-max))) | 2163 (sql-send-region (point-min) (point-max))) |
1217 | 2164 |
2165 (defun sql-send-string (str) | |
2166 "Send a string to the SQL process." | |
2167 (interactive "sSQL Text: ") | |
2168 (if (buffer-live-p sql-buffer) | |
2169 (save-excursion | |
2170 (comint-send-string sql-buffer str) | |
2171 (comint-send-string sql-buffer "\n") | |
2172 (message "Sent string to buffer %s." (buffer-name sql-buffer)) | |
2173 (if sql-pop-to-buffer-after-send-region | |
2174 (pop-to-buffer sql-buffer) | |
2175 (display-buffer sql-buffer))) | |
2176 (message "No SQL process started."))) | |
2177 | |
1218 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value) | 2178 (defun sql-toggle-pop-to-buffer-after-send-region (&optional value) |
1219 "Toggle `sql-pop-to-buffer-after-send-region'. | 2179 "Toggle `sql-pop-to-buffer-after-send-region'. |
1220 | 2180 |
1221 If given the optional parameter VALUE, sets | 2181 If given the optional parameter VALUE, sets |
1222 sql-toggle-pop-to-buffer-after-send-region to VALUE." | 2182 sql-toggle-pop-to-buffer-after-send-region to VALUE." |
1265 (use-local-map sql-mode-map) | 2225 (use-local-map sql-mode-map) |
1266 (if sql-mode-menu | 2226 (if sql-mode-menu |
1267 (easy-menu-add sql-mode-menu)); XEmacs | 2227 (easy-menu-add sql-mode-menu)); XEmacs |
1268 (set-syntax-table sql-mode-syntax-table) | 2228 (set-syntax-table sql-mode-syntax-table) |
1269 (make-local-variable 'font-lock-defaults) | 2229 (make-local-variable 'font-lock-defaults) |
1270 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try | 2230 (make-local-variable 'sql-mode-font-lock-keywords) |
1271 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column | |
1272 ;; will have just one quote. Therefore syntactic hilighting is | |
1273 ;; disabled for interactive buffers. `_' and `.' are considered part | |
1274 ;; of words. | |
1275 (setq font-lock-defaults '(sql-mode-font-lock-keywords | |
1276 nil t ((?_ . "w") (?. . "w")))) | |
1277 (make-local-variable 'comment-start) | 2231 (make-local-variable 'comment-start) |
1278 (setq comment-start "--") | 2232 (setq comment-start "--") |
1279 ;; Make each buffer in sql-mode remember the "current" SQLi buffer. | 2233 ;; Make each buffer in sql-mode remember the "current" SQLi buffer. |
1280 (make-local-variable 'sql-buffer) | 2234 (make-local-variable 'sql-buffer) |
1281 ;; Add imenu support for sql-mode. Note that imenu-generic-expression | 2235 ;; Add imenu support for sql-mode. Note that imenu-generic-expression |
1282 ;; is buffer-local, so we don't need a local-variable for it. SQL is | 2236 ;; is buffer-local, so we don't need a local-variable for it. SQL is |
1283 ;; case-insensitive, that's why we have to set imenu-case-fold-search. | 2237 ;; case-insensitive, that's why we have to set imenu-case-fold-search. |
1284 ;; imenu-syntax-alist makes sure that `_' is considered part of object | |
1285 ;; names. | |
1286 (setq imenu-generic-expression sql-imenu-generic-expression | 2238 (setq imenu-generic-expression sql-imenu-generic-expression |
1287 imenu-case-fold-search t | 2239 imenu-case-fold-search t) |
1288 imenu-syntax-alist '(("_" . "w"))) | |
1289 ;; Make `sql-send-paragraph' work on paragraphs that contain indented | 2240 ;; Make `sql-send-paragraph' work on paragraphs that contain indented |
1290 ;; lines. | 2241 ;; lines. |
1291 (make-local-variable 'paragraph-separate) | 2242 (make-local-variable 'paragraph-separate) |
1292 (make-local-variable 'paragraph-start) | 2243 (make-local-variable 'paragraph-start) |
1293 (setq paragraph-separate "[\f]*$" | 2244 (setq paragraph-separate "[\f]*$" |
1294 paragraph-start "[\n\f]") | 2245 paragraph-start "[\n\f]") |
1295 ;; Abbrevs | 2246 ;; Abbrevs |
1296 (setq local-abbrev-table sql-mode-abbrev-table) | 2247 (setq local-abbrev-table sql-mode-abbrev-table) |
1297 (setq abbrev-all-caps 1) | 2248 (setq abbrev-all-caps 1) |
1298 ;; Run hook | 2249 ;; Run hook |
1299 (run-hooks 'sql-mode-hook)) | 2250 (run-mode-hooks 'sql-mode-hook) |
2251 ;; Catch changes to sql-product and highlight accordingly | |
2252 (sql-highlight-product) | |
2253 (add-hook 'hack-local-variables-hook 'sql-highlight-product t t)) | |
1300 | 2254 |
1301 | 2255 |
1302 | 2256 |
1303 ;;; SQL interactive mode | 2257 ;;; SQL interactive mode |
1304 | 2258 |
1347 and `sql-interactive-mode-hook' (in that order). Before each input, the | 2301 and `sql-interactive-mode-hook' (in that order). Before each input, the |
1348 hooks on `comint-input-filter-functions' are run. After each SQL | 2302 hooks on `comint-input-filter-functions' are run. After each SQL |
1349 interpreter output, the hooks on `comint-output-filter-functions' are | 2303 interpreter output, the hooks on `comint-output-filter-functions' are |
1350 run. | 2304 run. |
1351 | 2305 |
1352 Variable `sql-input-ring-file-name' controls the initialisation of the | 2306 Variable `sql-input-ring-file-name' controls the initialization of the |
1353 input ring history. | 2307 input ring history. |
1354 | 2308 |
1355 Variables `comint-output-filter-functions', a hook, and | 2309 Variables `comint-output-filter-functions', a hook, and |
1356 `comint-scroll-to-bottom-on-input' and | 2310 `comint-scroll-to-bottom-on-input' and |
1357 `comint-scroll-to-bottom-on-output' control whether input and output | 2311 `comint-scroll-to-bottom-on-output' control whether input and output |
1370 Here is another example. It will always put point back to the statement | 2324 Here is another example. It will always put point back to the statement |
1371 you entered, right above the output it created. | 2325 you entered, right above the output it created. |
1372 | 2326 |
1373 \(setq comint-output-filter-functions | 2327 \(setq comint-output-filter-functions |
1374 \(function (lambda (STR) (comint-show-output))))" | 2328 \(function (lambda (STR) (comint-show-output))))" |
1375 (comint-mode) | 2329 (delay-mode-hooks (comint-mode)) |
1376 (setq comint-prompt-regexp sql-prompt-regexp) | 2330 ;; Get the `sql-product' for this interactive session. |
1377 (setq left-margin sql-prompt-length) | 2331 (set (make-local-variable 'sql-product) |
2332 (or sql-interactive-product | |
2333 sql-product)) | |
2334 ;; Setup the mode. | |
1378 (setq major-mode 'sql-interactive-mode) | 2335 (setq major-mode 'sql-interactive-mode) |
1379 (setq mode-name "SQLi") | 2336 (setq mode-name (concat "SQLi[" (prin1-to-string sql-product) "]")) |
1380 (use-local-map sql-interactive-mode-map) | 2337 (use-local-map sql-interactive-mode-map) |
1381 (if sql-interactive-mode-menu | 2338 (if sql-interactive-mode-menu |
1382 (easy-menu-add sql-interactive-mode-menu)); XEmacs | 2339 (easy-menu-add sql-interactive-mode-menu)) ; XEmacs |
1383 (set-syntax-table sql-mode-syntax-table) | 2340 (set-syntax-table sql-mode-syntax-table) |
2341 (make-local-variable 'sql-mode-font-lock-keywords) | |
1384 (make-local-variable 'font-lock-defaults) | 2342 (make-local-variable 'font-lock-defaults) |
1385 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try | 2343 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try |
1386 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column | 2344 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column |
1387 ;; will have just one quote. Therefore syntactic hilighting is | 2345 ;; will have just one quote. Therefore syntactic hilighting is |
1388 ;; disabled for interactive buffers. `_' and `.' are considered part | 2346 ;; disabled for interactive buffers. No imenu support. |
1389 ;; of words. | 2347 (sql-product-font-lock t nil) |
1390 (setq font-lock-defaults '(sql-mode-font-lock-keywords | |
1391 t t ((?_ . "w") (?. . "w")))) | |
1392 ;; Enable commenting and uncommenting of the region. | 2348 ;; Enable commenting and uncommenting of the region. |
1393 (make-local-variable 'comment-start) | 2349 (make-local-variable 'comment-start) |
1394 (setq comment-start "--") | 2350 (setq comment-start "--") |
1395 ;; Abbreviation table init and case-insensitive. It is not activatet | 2351 ;; Abbreviation table init and case-insensitive. It is not activated |
1396 ;; by default. | 2352 ;; by default. |
1397 (setq local-abbrev-table sql-mode-abbrev-table) | 2353 (setq local-abbrev-table sql-mode-abbrev-table) |
1398 (setq abbrev-all-caps 1) | 2354 (setq abbrev-all-caps 1) |
1399 ;; Exiting the process will call sql-stop. | 2355 ;; Exiting the process will call sql-stop. |
1400 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop) | 2356 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop) |
2357 ;; Create a usefull name for renaming this buffer later. | |
2358 (make-local-variable 'sql-alternate-buffer-name) | |
2359 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name)) | |
2360 ;; User stuff. Initialize before the hook. | |
2361 (set (make-local-variable 'sql-prompt-regexp) | |
2362 (sql-product-feature :sqli-prompt-regexp)) | |
2363 (set (make-local-variable 'sql-prompt-length) | |
2364 (sql-product-feature :sqli-prompt-length)) | |
2365 (make-local-variable 'sql-input-ring-separator) | |
2366 (make-local-variable 'sql-input-ring-file-name) | |
2367 ;; Run hook. | |
2368 (run-mode-hooks 'sql-interactive-mode-hook) | |
2369 ;; Set comint based on user overrides. | |
2370 (setq comint-prompt-regexp sql-prompt-regexp) | |
2371 (setq left-margin sql-prompt-length) | |
1401 ;; People wanting a different history file for each | 2372 ;; People wanting a different history file for each |
1402 ;; buffer/process/client/whatever can change separator and file-name | 2373 ;; buffer/process/client/whatever can change separator and file-name |
1403 ;; on the sql-interactive-mode-hook. | 2374 ;; on the sql-interactive-mode-hook. |
1404 (setq comint-input-ring-separator sql-input-ring-separator | 2375 (setq comint-input-ring-separator sql-input-ring-separator |
1405 comint-input-ring-file-name sql-input-ring-file-name) | 2376 comint-input-ring-file-name sql-input-ring-file-name) |
1406 ;; Create a usefull name for renaming this buffer later. | |
1407 (make-local-variable 'sql-alternate-buffer-name) | |
1408 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name)) | |
1409 ;; User stuff. | |
1410 (run-hooks 'sql-interactive-mode-hook) | |
1411 ;; Calling the hook before calling comint-read-input-ring allows users | 2377 ;; Calling the hook before calling comint-read-input-ring allows users |
1412 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook. | 2378 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook. |
1413 (comint-read-input-ring t)) | 2379 (comint-read-input-ring t)) |
1414 | 2380 |
1415 (defun sql-stop (process event) | 2381 (defun sql-stop (process event) |
1429 | 2395 |
1430 | 2396 |
1431 ;;; Entry functions for different SQL interpreters. | 2397 ;;; Entry functions for different SQL interpreters. |
1432 | 2398 |
1433 ;;;###autoload | 2399 ;;;###autoload |
2400 (defun sql-product-interactive (&optional product) | |
2401 "Run product interpreter as an inferior process. | |
2402 | |
2403 If buffer `*SQL*' exists but no process is running, make a new process. | |
2404 If buffer exists and a process is running, just switch to buffer | |
2405 `*SQL*'. | |
2406 | |
2407 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
2408 (interactive) | |
2409 (setq product (or product sql-product)) | |
2410 (when (sql-product-feature :sqli-connect product) | |
2411 (if (comint-check-proc "*SQL*") | |
2412 (pop-to-buffer "*SQL*") | |
2413 ;; Get credentials. | |
2414 (apply 'sql-get-login (sql-product-feature :sqli-login product)) | |
2415 ;; Connect to database. | |
2416 (message "Login...") | |
2417 (funcall (sql-product-feature :sqli-connect product)) | |
2418 ;; Set SQLi mode. | |
2419 (setq sql-interactive-product product) | |
2420 (setq sql-buffer (current-buffer)) | |
2421 (sql-interactive-mode) | |
2422 ;; All done. | |
2423 (message "Login...done") | |
2424 (pop-to-buffer sql-buffer)))) | |
2425 | |
2426 ;;;###autoload | |
1434 (defun sql-oracle () | 2427 (defun sql-oracle () |
1435 "Run sqlplus by Oracle as an inferior process. | 2428 "Run sqlplus by Oracle as an inferior process. |
1436 | 2429 |
1437 If buffer `*SQL*' exists but no process is running, make a new process. | 2430 If buffer `*SQL*' exists but no process is running, make a new process. |
1438 If buffer exists and a process is running, just switch to buffer | 2431 If buffer exists and a process is running, just switch to buffer |
1453 The default comes from `process-coding-system-alist' and | 2446 The default comes from `process-coding-system-alist' and |
1454 `default-process-coding-system'. | 2447 `default-process-coding-system'. |
1455 | 2448 |
1456 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2449 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1457 (interactive) | 2450 (interactive) |
1458 (if (comint-check-proc "*SQL*") | 2451 (sql-product-interactive 'oracle)) |
1459 (pop-to-buffer "*SQL*") | 2452 |
1460 (sql-get-login 'user 'password 'database) | 2453 (defun sql-connect-oracle () |
1461 (message "Login...") | 2454 "Create comint buffer and connect to Oracle using the login |
1462 ;; Produce user/password@database construct. Password without user | 2455 parameters and command options." |
1463 ;; is meaningless; database without user/password is meaningless, | 2456 ;; Produce user/password@database construct. Password without user |
1464 ;; because "@param" will ask sqlplus to interpret the script | 2457 ;; is meaningless; database without user/password is meaningless, |
1465 ;; "param". | 2458 ;; because "@param" will ask sqlplus to interpret the script |
1466 (let ((parameter nil)) | 2459 ;; "param". |
1467 (if (not (string= "" sql-user)) | 2460 (let ((parameter nil)) |
1468 (if (not (string= "" sql-password)) | 2461 (if (not (string= "" sql-user)) |
1469 (setq parameter (concat sql-user "/" sql-password)) | 2462 (if (not (string= "" sql-password)) |
1470 (setq parameter sql-user))) | 2463 (setq parameter (concat sql-user "/" sql-password)) |
1471 (if (and parameter (not (string= "" sql-database))) | 2464 (setq parameter sql-user))) |
1472 (setq parameter (concat parameter "@" sql-database))) | 2465 (if (and parameter (not (string= "" sql-database))) |
1473 (if parameter | 2466 (setq parameter (concat parameter "@" sql-database))) |
1474 (setq parameter (nconc (list parameter) sql-oracle-options)) | 2467 (if parameter |
1475 (setq parameter sql-oracle-options)) | 2468 (setq parameter (nconc (list parameter) sql-oracle-options)) |
1476 (if parameter | 2469 (setq parameter sql-oracle-options)) |
1477 (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil | 2470 (if parameter |
1478 parameter)) | 2471 (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil |
1479 (set-buffer (make-comint "SQL" sql-oracle-program nil)))) | 2472 parameter)) |
1480 (setq sql-prompt-regexp "^SQL> ") | 2473 (set-buffer (make-comint "SQL" sql-oracle-program nil))) |
1481 (setq sql-prompt-length 5) | 2474 ;; SQL*Plus is buffered on WindowsNT; this handles &placeholders. |
1482 (setq sql-buffer (current-buffer)) | |
1483 ;; set sql-mode-font-lock-keywords to something different before | |
1484 ;; calling sql-interactive-mode. | |
1485 (setq sql-mode-font-lock-keywords sql-mode-oracle-font-lock-keywords) | |
1486 (sql-interactive-mode) | |
1487 ;; If running on NT, make sure we do placeholder replacement | |
1488 ;; ourselves. This must come after sql-interactive-mode because all | |
1489 ;; local variables will be killed, there. | |
1490 (if (eq window-system 'w32) | 2475 (if (eq window-system 'w32) |
1491 (setq comint-input-sender 'sql-query-placeholders-and-send)) | 2476 (setq comint-input-sender 'sql-query-placeholders-and-send)))) |
1492 (message "Login...done") | |
1493 (pop-to-buffer sql-buffer))) | |
1494 | 2477 |
1495 | 2478 |
1496 | 2479 |
1497 ;;;###autoload | 2480 ;;;###autoload |
1498 (defun sql-sybase () | 2481 (defun sql-sybase () |
1517 The default comes from `process-coding-system-alist' and | 2500 The default comes from `process-coding-system-alist' and |
1518 `default-process-coding-system'. | 2501 `default-process-coding-system'. |
1519 | 2502 |
1520 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2503 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1521 (interactive) | 2504 (interactive) |
1522 (if (comint-check-proc "*SQL*") | 2505 (sql-product-interactive 'sybase)) |
1523 (pop-to-buffer "*SQL*") | 2506 |
1524 (sql-get-login 'server 'user 'password 'database) | 2507 (defun sql-connect-sybase () |
1525 (message "Login...") | 2508 "Create comint buffer and connect to Sybase using the login |
1526 ;; Put all parameters to the program (if defined) in a list and call | 2509 parameters and command options." |
1527 ;; make-comint. | 2510 ;; Put all parameters to the program (if defined) in a list and call |
1528 (let ((params sql-sybase-options)) | 2511 ;; make-comint. |
1529 (if (not (string= "" sql-server)) | 2512 (let ((params sql-sybase-options)) |
1530 (setq params (append (list "-S" sql-server) params))) | 2513 (if (not (string= "" sql-server)) |
1531 (if (not (string= "" sql-database)) | 2514 (setq params (append (list "-S" sql-server) params))) |
1532 (setq params (append (list "-D" sql-database) params))) | 2515 (if (not (string= "" sql-database)) |
1533 (if (not (string= "" sql-password)) | 2516 (setq params (append (list "-D" sql-database) params))) |
1534 (setq params (append (list "-P" sql-password) params))) | 2517 (if (not (string= "" sql-password)) |
1535 (if (not (string= "" sql-user)) | 2518 (setq params (append (list "-P" sql-password) params))) |
1536 (setq params (append (list "-U" sql-user) params))) | 2519 (if (not (string= "" sql-user)) |
1537 (set-buffer (apply 'make-comint "SQL" sql-sybase-program | 2520 (setq params (append (list "-U" sql-user) params))) |
1538 nil params))) | 2521 (set-buffer (apply 'make-comint "SQL" sql-sybase-program |
1539 (setq sql-prompt-regexp "^SQL> ") | 2522 nil params)))) |
1540 (setq sql-prompt-length 5) | |
1541 (setq sql-buffer (current-buffer)) | |
1542 (sql-interactive-mode) | |
1543 (message "Login...done") | |
1544 (pop-to-buffer sql-buffer))) | |
1545 | 2523 |
1546 | 2524 |
1547 | 2525 |
1548 ;;;###autoload | 2526 ;;;###autoload |
1549 (defun sql-informix () | 2527 (defun sql-informix () |
1566 The default comes from `process-coding-system-alist' and | 2544 The default comes from `process-coding-system-alist' and |
1567 `default-process-coding-system'. | 2545 `default-process-coding-system'. |
1568 | 2546 |
1569 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2547 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1570 (interactive) | 2548 (interactive) |
1571 (if (comint-check-proc "*SQL*") | 2549 (sql-product-interactive 'informix)) |
1572 (pop-to-buffer "*SQL*") | 2550 |
1573 (sql-get-login 'database) | 2551 (defun sql-connect-informix () |
1574 (message "Login...") | 2552 "Create comint buffer and connect to Informix using the login |
1575 ;; username and password are ignored. | 2553 parameters and command options." |
1576 (if (string= "" sql-database) | 2554 ;; username and password are ignored. |
1577 (set-buffer (make-comint "SQL" sql-informix-program nil)) | 2555 (if (string= "" sql-database) |
1578 (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-"))) | 2556 (set-buffer (make-comint "SQL" sql-informix-program nil)) |
1579 (setq sql-prompt-regexp "^SQL> ") | 2557 (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-")))) |
1580 (setq sql-prompt-length 5) | 2558 |
1581 (setq sql-buffer (current-buffer)) | 2559 |
1582 (sql-interactive-mode) | 2560 |
1583 (message "Login...done") | 2561 ;;;###autoload |
1584 (pop-to-buffer sql-buffer))) | 2562 (defun sql-sqlite () |
2563 "Run sqlite as an inferior process. | |
2564 | |
2565 SQLite is free software. | |
2566 | |
2567 If buffer `*SQL*' exists but no process is running, make a new process. | |
2568 If buffer exists and a process is running, just switch to buffer | |
2569 `*SQL*'. | |
2570 | |
2571 Interpreter used comes from variable `sql-sqlite-program'. Login uses | |
2572 the variables `sql-user', `sql-password', `sql-database', and | |
2573 `sql-server' as defaults, if set. Additional command line parameters | |
2574 can be stored in the list `sql-sqlite-options'. | |
2575 | |
2576 The buffer is put in sql-interactive-mode, giving commands for sending | |
2577 input. See `sql-interactive-mode'. | |
2578 | |
2579 To specify a coding system for converting non-ASCII characters | |
2580 in the input and output to the process, use \\[universal-coding-system-argument] | |
2581 before \\[sql-sqlite]. You can also specify this with \\[set-buffer-process-coding-system] | |
2582 in the SQL buffer, after you start the process. | |
2583 The default comes from `process-coding-system-alist' and | |
2584 `default-process-coding-system'. | |
2585 | |
2586 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | |
2587 (interactive) | |
2588 (sql-product-interactive 'sqlite)) | |
2589 | |
2590 (defun sql-connect-sqlite () | |
2591 "Create comint buffer and connect to SQLite using the login | |
2592 parameters and command options." | |
2593 ;; Put all parameters to the program (if defined) in a list and call | |
2594 ;; make-comint. | |
2595 (let ((params)) | |
2596 (if (not (string= "" sql-database)) | |
2597 (setq params (append (list sql-database) params))) | |
2598 (if (not (string= "" sql-server)) | |
2599 (setq params (append (list (concat "--host=" sql-server)) params))) | |
2600 (if (not (string= "" sql-password)) | |
2601 (setq params (append (list (concat "--password=" sql-password)) params))) | |
2602 (if (not (string= "" sql-user)) | |
2603 (setq params (append (list (concat "--user=" sql-user)) params))) | |
2604 (if (not (null sql-sqlite-options)) | |
2605 (setq params (append sql-sqlite-options params))) | |
2606 (set-buffer (apply 'make-comint "SQL" sql-sqlite-program | |
2607 nil params)))) | |
1585 | 2608 |
1586 | 2609 |
1587 | 2610 |
1588 ;;;###autoload | 2611 ;;;###autoload |
1589 (defun sql-mysql () | 2612 (defun sql-mysql () |
1610 The default comes from `process-coding-system-alist' and | 2633 The default comes from `process-coding-system-alist' and |
1611 `default-process-coding-system'. | 2634 `default-process-coding-system'. |
1612 | 2635 |
1613 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2636 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1614 (interactive) | 2637 (interactive) |
1615 (if (comint-check-proc "*SQL*") | 2638 (sql-product-interactive 'mysql)) |
1616 (pop-to-buffer "*SQL*") | 2639 |
1617 (sql-get-login 'user 'password 'database 'server) | 2640 (defun sql-connect-mysql () |
1618 (message "Login...") | 2641 "Create comint buffer and connect to MySQL using the login |
1619 ;; Put all parameters to the program (if defined) in a list and call | 2642 parameters and command options." |
1620 ;; make-comint. | 2643 ;; Put all parameters to the program (if defined) in a list and call |
1621 (let ((params)) | 2644 ;; make-comint. |
1622 (if (not (string= "" sql-database)) | 2645 (let ((params)) |
1623 (setq params (append (list sql-database) params))) | 2646 (if (not (string= "" sql-database)) |
1624 (if (not (string= "" sql-server)) | 2647 (setq params (append (list sql-database) params))) |
1625 (setq params (append (list (concat "--host=" sql-server)) params))) | 2648 (if (not (string= "" sql-server)) |
1626 (if (not (string= "" sql-password)) | 2649 (setq params (append (list (concat "--host=" sql-server)) params))) |
1627 (setq params (append (list (concat "--password=" sql-password)) params))) | 2650 (if (not (string= "" sql-password)) |
1628 (if (not (string= "" sql-user)) | 2651 (setq params (append (list (concat "--password=" sql-password)) params))) |
1629 (setq params (append (list (concat "--user=" sql-user)) params))) | 2652 (if (not (string= "" sql-user)) |
1630 (if (not (null sql-mysql-options)) | 2653 (setq params (append (list (concat "--user=" sql-user)) params))) |
1631 (setq params (append sql-mysql-options params))) | 2654 (if (not (null sql-mysql-options)) |
1632 (set-buffer (apply 'make-comint "SQL" sql-mysql-program | 2655 (setq params (append sql-mysql-options params))) |
1633 nil params))) | 2656 (set-buffer (apply 'make-comint "SQL" sql-mysql-program |
1634 (setq sql-prompt-regexp "^mysql>") | 2657 nil params)))) |
1635 (setq sql-prompt-length 6) | |
1636 (setq sql-buffer (current-buffer)) | |
1637 (sql-interactive-mode) | |
1638 (message "Login...done") | |
1639 (pop-to-buffer sql-buffer))) | |
1640 | 2658 |
1641 | 2659 |
1642 | 2660 |
1643 ;;;###autoload | 2661 ;;;###autoload |
1644 (defun sql-solid () | 2662 (defun sql-solid () |
1662 The default comes from `process-coding-system-alist' and | 2680 The default comes from `process-coding-system-alist' and |
1663 `default-process-coding-system'. | 2681 `default-process-coding-system'. |
1664 | 2682 |
1665 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2683 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1666 (interactive) | 2684 (interactive) |
1667 (if (comint-check-proc "*SQL*") | 2685 (sql-product-interactive 'solid)) |
1668 (pop-to-buffer "*SQL*") | 2686 |
1669 (sql-get-login 'user 'password 'server) | 2687 (defun sql-connect-solid () |
1670 (message "Login...") | 2688 "Create comint buffer and connect to Solid using the login |
1671 ;; Put all parameters to the program (if defined) in a list and call | 2689 parameters and command options." |
1672 ;; make-comint. | 2690 ;; Put all parameters to the program (if defined) in a list and call |
1673 (let ((params)) | 2691 ;; make-comint. |
1674 ;; It only makes sense if both username and password are there. | 2692 (let ((params)) |
1675 (if (not (or (string= "" sql-user) | 2693 ;; It only makes sense if both username and password are there. |
1676 (string= "" sql-password))) | 2694 (if (not (or (string= "" sql-user) |
1677 (setq params (append (list sql-user sql-password) params))) | 2695 (string= "" sql-password))) |
1678 (if (not (string= "" sql-server)) | 2696 (setq params (append (list sql-user sql-password) params))) |
1679 (setq params (append (list sql-server) params))) | 2697 (if (not (string= "" sql-server)) |
1680 (set-buffer (apply 'make-comint "SQL" sql-solid-program | 2698 (setq params (append (list sql-server) params))) |
1681 nil params))) | 2699 (set-buffer (apply 'make-comint "SQL" sql-solid-program |
1682 (setq sql-prompt-regexp "^") | 2700 nil params)))) |
1683 (setq sql-prompt-length 0) | |
1684 (setq sql-buffer (current-buffer)) | |
1685 (sql-interactive-mode) | |
1686 (message "Login...done") | |
1687 (pop-to-buffer sql-buffer))) | |
1688 | 2701 |
1689 | 2702 |
1690 | 2703 |
1691 ;;;###autoload | 2704 ;;;###autoload |
1692 (defun sql-ingres () | 2705 (defun sql-ingres () |
1709 The default comes from `process-coding-system-alist' and | 2722 The default comes from `process-coding-system-alist' and |
1710 `default-process-coding-system'. | 2723 `default-process-coding-system'. |
1711 | 2724 |
1712 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2725 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1713 (interactive) | 2726 (interactive) |
1714 (if (comint-check-proc "*SQL*") | 2727 (sql-product-interactive 'ingres)) |
1715 (pop-to-buffer "*SQL*") | 2728 |
1716 (sql-get-login 'database) | 2729 (defun sql-connect-ingres () |
1717 (message "Login...") | 2730 "Create comint buffer and connect to Ingres using the login |
1718 ;; username and password are ignored. | 2731 parameters and command options." |
1719 (if (string= "" sql-database) | 2732 ;; username and password are ignored. |
1720 (set-buffer (make-comint "SQL" sql-ingres-program nil)) | 2733 (if (string= "" sql-database) |
1721 (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database))) | 2734 (set-buffer (make-comint "SQL" sql-ingres-program nil)) |
1722 (setq sql-prompt-regexp "^\* ") | 2735 (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database)))) |
1723 (setq sql-prompt-length 2) | |
1724 (setq sql-buffer (current-buffer)) | |
1725 (sql-interactive-mode) | |
1726 (message "Login...done") | |
1727 (pop-to-buffer sql-buffer))) | |
1728 | 2736 |
1729 | 2737 |
1730 | 2738 |
1731 ;;;###autoload | 2739 ;;;###autoload |
1732 (defun sql-ms () | 2740 (defun sql-ms () |
1733 "Run isql by Microsoft as an inferior process. | 2741 "Run osql by Microsoft as an inferior process. |
1734 | 2742 |
1735 If buffer `*SQL*' exists but no process is running, make a new process. | 2743 If buffer `*SQL*' exists but no process is running, make a new process. |
1736 If buffer exists and a process is running, just switch to buffer | 2744 If buffer exists and a process is running, just switch to buffer |
1737 `*SQL*'. | 2745 `*SQL*'. |
1738 | 2746 |
1751 The default comes from `process-coding-system-alist' and | 2759 The default comes from `process-coding-system-alist' and |
1752 `default-process-coding-system'. | 2760 `default-process-coding-system'. |
1753 | 2761 |
1754 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2762 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1755 (interactive) | 2763 (interactive) |
1756 (if (comint-check-proc "*SQL*") | 2764 (sql-product-interactive 'ms)) |
1757 (pop-to-buffer "*SQL*") | 2765 |
1758 (sql-get-login 'user 'password 'database 'server) | 2766 (defun sql-connect-ms () |
1759 (message "Login...") | 2767 "Create comint buffer and connect to Microsoft using the login |
1760 ;; Put all parameters to the program (if defined) in a list and call | 2768 parameters and command options." |
1761 ;; make-comint. | 2769 ;; Put all parameters to the program (if defined) in a list and call |
1762 (let ((params sql-ms-options)) | 2770 ;; make-comint. |
1763 (if (not (string= "" sql-server)) | 2771 (let ((params sql-ms-options)) |
2772 (if (not (string= "" sql-server)) | |
1764 (setq params (append (list "-S" sql-server) params))) | 2773 (setq params (append (list "-S" sql-server) params))) |
1765 (if (not (string= "" sql-database)) | 2774 (if (not (string= "" sql-database)) |
1766 (setq params (append (list "-d" sql-database) params))) | 2775 (setq params (append (list "-d" sql-database) params))) |
1767 (if (not (string= "" sql-user)) | 2776 (if (not (string= "" sql-user)) |
1768 (setq params (append (list "-U" sql-user) params))) | 2777 (setq params (append (list "-U" sql-user) params))) |
1769 (if (not (string= "" sql-password)) | 2778 (if (not (string= "" sql-password)) |
1770 (setq params (append (list "-P" sql-password) params)) | 2779 (setq params (append (list "-P" sql-password) params)) |
1771 ;; If -P is passed to ISQL as the last argument without a password, | 2780 (if (string= "" sql-user) |
1772 ;; it's considered null. | 2781 ;; if neither user nor password is provided, use system |
1773 (setq params (append params (list "-P")))) | 2782 ;; credentials. |
1774 (set-buffer (apply 'make-comint "SQL" sql-ms-program | 2783 (setq params (append (list "-E") params)) |
1775 nil params))) | 2784 ;; If -P is passed to ISQL as the last argument without a |
1776 (setq sql-prompt-regexp "^[0-9]*>") | 2785 ;; password, it's considered null. |
1777 (setq sql-prompt-length 5) | 2786 (setq params (append params (list "-P"))))) |
1778 (setq sql-buffer (current-buffer)) | 2787 (set-buffer (apply 'make-comint "SQL" sql-ms-program |
1779 (sql-interactive-mode) | 2788 nil params)))) |
1780 (message "Login...done") | |
1781 (pop-to-buffer sql-buffer))) | |
1782 | 2789 |
1783 | 2790 |
1784 | 2791 |
1785 ;;;###autoload | 2792 ;;;###autoload |
1786 (defun sql-postgres () | 2793 (defun sql-postgres () |
1810 \(setq comint-output-filter-functions (append comint-output-filter-functions | 2817 \(setq comint-output-filter-functions (append comint-output-filter-functions |
1811 '(comint-strip-ctrl-m))) | 2818 '(comint-strip-ctrl-m))) |
1812 | 2819 |
1813 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2820 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1814 (interactive) | 2821 (interactive) |
1815 (if (comint-check-proc "*SQL*") | 2822 (sql-product-interactive 'postgres)) |
1816 (pop-to-buffer "*SQL*") | 2823 |
1817 (sql-get-login 'database 'server) | 2824 (defun sql-connect-postgres () |
1818 (message "Login...") | 2825 "Create comint buffer and connect to Postgres using the login |
1819 ;; username and password are ignored. Mark Stosberg suggest to add | 2826 parameters and command options." |
1820 ;; the database at the end. Jason Beegan suggest using --pset and | 2827 ;; username and password are ignored. Mark Stosberg suggest to add |
1821 ;; pager=off instead of \\o|cat. The later was the solution by | 2828 ;; the database at the end. Jason Beegan suggest using --pset and |
1822 ;; Gregor Zych. Jason's suggestion is the default value for | 2829 ;; pager=off instead of \\o|cat. The later was the solution by |
1823 ;; sql-postgres-options. | 2830 ;; Gregor Zych. Jason's suggestion is the default value for |
1824 (let ((params sql-postgres-options)) | 2831 ;; sql-postgres-options. |
1825 (if (not (string= "" sql-database)) | 2832 (let ((params sql-postgres-options)) |
1826 (setq params (append params (list sql-database)))) | 2833 (if (not (string= "" sql-database)) |
1827 (if (not (string= "" sql-server)) | 2834 (setq params (append params (list sql-database)))) |
1828 (setq params (append (list "-h" sql-server) params))) | 2835 (if (not (string= "" sql-server)) |
1829 (set-buffer (apply 'make-comint "SQL" sql-postgres-program | 2836 (setq params (append (list "-h" sql-server) params))) |
1830 nil params))) | 2837 (if (not (string= "" sql-user)) |
1831 (setq sql-prompt-regexp "^.*> *") | 2838 (setq params (append (list "-U" sql-user) params))) |
1832 (setq sql-prompt-length 5) | 2839 (set-buffer (apply 'make-comint "SQL" sql-postgres-program |
1833 ;; This is a lousy hack to prevent psql from truncating it's output | 2840 nil params)))) |
1834 ;; and giving stupid warnings. If s.o. knows a way to prevent psql | |
1835 ;; from acting this way, then I would be very thankful to | |
1836 ;; incorporate this (Gregor Zych <zych@pool.informatik.rwth-aachen.de>) | |
1837 ;; (comint-send-string "*SQL*" "\\o \| cat\n") | |
1838 (setq sql-mode-font-lock-keywords sql-mode-postgres-font-lock-keywords) | |
1839 (setq sql-buffer (current-buffer)) | |
1840 (sql-interactive-mode) | |
1841 (message "Login...done") | |
1842 (pop-to-buffer sql-buffer))) | |
1843 | 2841 |
1844 | 2842 |
1845 | 2843 |
1846 ;;;###autoload | 2844 ;;;###autoload |
1847 (defun sql-interbase () | 2845 (defun sql-interbase () |
1865 The default comes from `process-coding-system-alist' and | 2863 The default comes from `process-coding-system-alist' and |
1866 `default-process-coding-system'. | 2864 `default-process-coding-system'. |
1867 | 2865 |
1868 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2866 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1869 (interactive) | 2867 (interactive) |
1870 (if (comint-check-proc "*SQL*") | 2868 (sql-product-interactive 'interbase)) |
1871 (pop-to-buffer "*SQL*") | 2869 |
1872 (sql-get-login 'user 'password 'database) | 2870 (defun sql-connect-interbase () |
1873 (message "Login...") | 2871 "Create comint buffer and connect to Interbase using the login |
1874 ;; Put all parameters to the program (if defined) in a list and call | 2872 parameters and command options." |
1875 ;; make-comint. | 2873 ;; Put all parameters to the program (if defined) in a list and call |
1876 (let ((params sql-interbase-options)) | 2874 ;; make-comint. |
1877 (if (not (string= "" sql-user)) | 2875 (let ((params sql-interbase-options)) |
1878 (setq params (append (list "-u" sql-user) params))) | 2876 (if (not (string= "" sql-user)) |
1879 (if (not (string= "" sql-password)) | 2877 (setq params (append (list "-u" sql-user) params))) |
1880 (setq params (append (list "-p" sql-password) params))) | 2878 (if (not (string= "" sql-password)) |
1881 (if (not (string= "" sql-database)) | 2879 (setq params (append (list "-p" sql-password) params))) |
1882 (setq params (cons sql-database params))); add to the front! | 2880 (if (not (string= "" sql-database)) |
1883 (set-buffer (apply 'make-comint "SQL" sql-interbase-program | 2881 (setq params (cons sql-database params))) ; add to the front! |
1884 nil params))) | 2882 (set-buffer (apply 'make-comint "SQL" sql-interbase-program |
1885 (setq sql-prompt-regexp "^SQL> ") | 2883 nil params)))) |
1886 (setq sql-prompt-length 5) | |
1887 (setq sql-buffer (current-buffer)) | |
1888 (sql-interactive-mode) | |
1889 (message "Login...done") | |
1890 (pop-to-buffer sql-buffer))) | |
1891 | 2884 |
1892 | 2885 |
1893 | 2886 |
1894 ;;;###autoload | 2887 ;;;###autoload |
1895 (defun sql-db2 () | 2888 (defun sql-db2 () |
1917 The default comes from `process-coding-system-alist' and | 2910 The default comes from `process-coding-system-alist' and |
1918 `default-process-coding-system'. | 2911 `default-process-coding-system'. |
1919 | 2912 |
1920 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2913 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1921 (interactive) | 2914 (interactive) |
1922 (if (comint-check-proc "*SQL*") | 2915 (sql-product-interactive 'db2)) |
1923 (pop-to-buffer "*SQL*") | 2916 |
1924 (message "Login...") | 2917 (defun sql-connect-db2 () |
1925 ;; Put all parameters to the program (if defined) in a list and call | 2918 "Create comint buffer and connect to DB2 using the login |
1926 ;; make-comint. | 2919 parameters and command options." |
1927 (set-buffer (apply 'make-comint "SQL" sql-db2-program | 2920 ;; Put all parameters to the program (if defined) in a list and call |
1928 nil sql-db2-options)) | 2921 ;; make-comint. |
1929 (setq sql-prompt-regexp "^db2 => ") | 2922 (set-buffer (apply 'make-comint "SQL" sql-db2-program |
1930 (setq sql-prompt-length 7) | 2923 nil sql-db2-options)) |
1931 (setq sql-buffer (current-buffer)) | 2924 ;; Properly escape newlines when DB2 is interactive. |
1932 (sql-interactive-mode) | 2925 (setq comint-input-sender 'sql-escape-newlines-and-send)) |
1933 ;; Escape newlines. This must come after sql-interactive-mode | |
1934 ;; because all local variables will be killed, there. | |
1935 (setq comint-input-sender 'sql-escape-newlines-and-send) | |
1936 (message "Login...done") | |
1937 (pop-to-buffer sql-buffer))) | |
1938 | 2926 |
1939 ;;;###autoload | 2927 ;;;###autoload |
1940 (defun sql-linter () | 2928 (defun sql-linter () |
1941 "Run inl by RELEX as an inferior process. | 2929 "Run inl by RELEX as an inferior process. |
1942 | 2930 |
1957 an empty password. | 2945 an empty password. |
1958 | 2946 |
1959 The buffer is put in sql-interactive-mode, giving commands for sending | 2947 The buffer is put in sql-interactive-mode, giving commands for sending |
1960 input. See `sql-interactive-mode'. | 2948 input. See `sql-interactive-mode'. |
1961 | 2949 |
1962 To use LINTER font locking by default, put this line into your .emacs : | |
1963 (setq sql-mode-font-lock-keywords sql-mode-linter-font-lock-keywords) | |
1964 | |
1965 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | 2950 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" |
1966 (interactive) | 2951 (interactive) |
1967 (if (comint-check-proc "*SQL*") | 2952 (sql-product-interactive 'linter)) |
1968 (pop-to-buffer "*SQL*") | 2953 |
1969 (sql-get-login 'user 'password 'database 'server) | 2954 (defun sql-connect-linter () |
1970 (message "Login...") | 2955 "Create comint buffer and connect to Linter using the login |
1971 ;; Put all parameters to the program (if defined) in a list and call | 2956 parameters and command options." |
1972 ;; make-comint. | 2957 ;; Put all parameters to the program (if defined) in a list and call |
1973 (let ((params sql-linter-options) (login nil) (old-mbx (getenv "LINTER_MBX"))) | 2958 ;; make-comint. |
1974 (if (not (string= "" sql-user)) | 2959 (let ((params sql-linter-options) (login nil) (old-mbx (getenv "LINTER_MBX"))) |
1975 (setq login (concat sql-user "/" sql-password))) | 2960 (if (not (string= "" sql-user)) |
1976 (setq params (append (list "-u" login) params)) | 2961 (setq login (concat sql-user "/" sql-password))) |
1977 (if (not (string= "" sql-server)) | 2962 (setq params (append (list "-u" login) params)) |
1978 (setq params (append (list "-n" sql-server) params))) | 2963 (if (not (string= "" sql-server)) |
1979 (if (string= "" sql-database) | 2964 (setq params (append (list "-n" sql-server) params))) |
1980 (setenv "LINTER_MBX" nil) | 2965 (if (string= "" sql-database) |
1981 (setenv "LINTER_MBX" sql-database)) | 2966 (setenv "LINTER_MBX" nil) |
1982 (set-buffer (apply 'make-comint "SQL" sql-linter-program nil | 2967 (setenv "LINTER_MBX" sql-database)) |
1983 params)) | 2968 (set-buffer (apply 'make-comint "SQL" sql-linter-program nil |
1984 (setenv "LINTER_MBX" old-mbx) | 2969 params)) |
1985 ) | 2970 (setenv "LINTER_MBX" old-mbx))) |
1986 (setq sql-prompt-regexp "^SQL>") | |
1987 (setq sql-prompt-length 4) | |
1988 (setq sql-buffer (current-buffer)) | |
1989 (sql-interactive-mode) | |
1990 (message "Login...done") | |
1991 (pop-to-buffer sql-buffer))) | |
1992 | 2971 |
1993 | 2972 |
1994 | 2973 |
1995 (provide 'sql) | 2974 (provide 'sql) |
1996 | 2975 |
2976 ;;; arch-tag: 7e1fa1c4-9ca2-402e-87d2-83a5eccb7ac3 | |
1997 ;;; sql.el ends here | 2977 ;;; sql.el ends here |