aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/sql.el
diff options
context:
space:
mode:
authorJuanma Barranquero2003-07-13 17:19:18 +0000
committerJuanma Barranquero2003-07-13 17:19:18 +0000
commit9c7bda2fc14caff147f535af58a60a9bbbb0fda3 (patch)
tree83c6389e8eb0bc96c5e30e3658f6d8cf3b5a04d4 /lisp/progmodes/sql.el
parent7e734986ab48dfda91450d672d5f701959d17569 (diff)
downloademacs-9c7bda2fc14caff147f535af58a60a9bbbb0fda3.tar.gz
emacs-9c7bda2fc14caff147f535af58a60a9bbbb0fda3.zip
Version 1.8.0 of sql-mode.
Simplify selection of SQL products to define highlighting and interactive mode. Includes detailed instructions on adding support for new products. (sql-product): New variable. Identifies SQL product for use in highlighting and interactive mode. (sql-interactive-product): New variable. SQL product for sql-interactive-mode. (sql-product-support): New variable. Specifies product-specific parameters to drive highlighting and interactive mode. (sql-imenu-generic-expression): Add more object types. (sql-sqlite-options): Correct comment. (sql-ms-program): Use "osql" rather than "isql". (sql-prompt-regexp, sql-prompt-length): Update comment. (sql-mode-menu): Add "Start SQLi session" entry. Replace Highlighting submenu with Product menu. Fix Send Region entry. (sql-mode-abbrev-table): Add abbreviations. Support of SYSTEM-FLAG on define-abbrev. Support was removed with last check-in; it now handles older Emacsen without the SYSTEM-FLAG. (sql-mode-font-lock-object-name): Add font-lock pattern for object names. (sql-mode-ansi-font-lock-keywords): Set as default value. (sql-mode-oracle-font-lock-keywords): Set as default value. Support Oracle 9i keywords. (sql-mode-postgres-font-lock-keywords): Set as default value. (sql-mode-linter-font-lock-keywords): Set as default value. (sql-mode-ms-font-lock-keywords): New variable. Support Microsoft SQLServer 2000. (sql-mode-sybase-font-lock-keywords) (sql-mode-interbase-font-lock-keywords) (sql-mode-sqlite-font-lock-keywords) (sql-mode-strong-font-lock-keywords) (sql-mode-mysql-font-lock-keywords) (sql-mode-db2-font-lock-keywords): New variables. Default to ANSI keywords. (sql-mode-font-lock-defaults): Update comment. (sql-product-feature): New function. Returns feature associated with a product from `sql-product-support' alist. (sql-product-font-lock): New function. Set font-lock support based on `sql-product'. (sql-add-product-keywords): New function. Add font-lock rules to product-specific keyword variables. (sql-set-product): New function. Set `sql-product' and apply appropriate font-lock highlighting. (sql-highlight-product): New function. Set font-lock support based on a product. Also set mode name to include product name. (sql-highlight-ansi-keywords, sql-highlight-oracle-keywords) (sql-highlight-postgres-keywords, sql-highlight-linter-keywords): Use `sql-set-product'. (sql-highlight-ms-keywords) (sql-highlight-sybase-keywords) (sql-highlight-interbase-keywords) (sql-highlight-strong-keywords) (sql-highlight-mysql-keywords) (sql-highlight-sqlite-keywords) (sql-highlight-db2-keywords): New functions. Use `sql-set-product'. (sql-get-login): Prompt in the same order as the tokens. (sql-mode): Uses `sql-product-highlight' and `sql-product-font-lock'. (sql-product-interactive): New function. Common portions of product-specific interactive mode wrappers. (sql-interactive-mode): Rewritten to use product features. (sql-oracle, sql-sybase, sql-informix, sql-sqlite, sql-mysql) (sql-solid, sql-ingres, sql-ms, sql-postgres, sql-interbase) (sql-db2, sql-linter): Use `sql-product-interactive'. (sql-connect-oracle, sql-connect-sybase, sql-connect-informix) (sql-connect-sqlite, sql-connect-mysql, sql-connect-solid) (sql-connect-ingres, sql-connect-postgres) (sql-connect-interbase, sql-connect-db2, sql-connect-linter): New functions. Format command line parameters and invoke comint on the appropriate interpreter. Code was in the corresponding `sql-xyz' function before. (sql-connect-ms): New function. Support -E argument to use operating system credentials for authentication.
Diffstat (limited to 'lisp/progmodes/sql.el')
-rw-r--r--lisp/progmodes/sql.el1026
1 files changed, 870 insertions, 156 deletions
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 4be9ec903f6..420f4d41613 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -1,10 +1,10 @@
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 Free Software Foundation, Inc.
4 4
5;; Author: Alex Schroeder <alex@gnu.org> 5;; Author: Alex Schroeder <alex@gnu.org>
6;; Maintainer: Alex Schroeder <alex@gnu.org> 6;; Maintainer: Alex Schroeder <alex@gnu.org>
7;; Version: 1.7.0 7;; Version: 1.8.0
8;; Keywords: comm languages processes 8;; Keywords: comm languages processes
9;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode 9;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode
10 10
@@ -78,24 +78,114 @@
78 78
79;;; Bugs: 79;;; Bugs:
80 80
81;; Using sql-ms (isql by Microsoft): When commands with syntax errors 81;; sql-ms now uses osql instead of isql. Osql flushes its error
82;; or execution errors are executed, there is no server feedback. 82;; stream more frequently than isql so that error messages are
83;; This happens in stored procedures for example. The server messages 83;; available. There is no prompt and some output still is buffered.
84;; only appear after the process is exited. This makes things 84;; This improves the interaction under Emacs but it still is somewhat
85;; somewhat unreliable. 85;; awkward.
86 86
87;; ChangeLog available on request. 87;; Quoted identifiers are not supported for hilighting. Most
88 88;; databases support the use of double quoted strings in place of
89;;; To Do: 89;; identifiers; ms (Microsoft SQLServer) also supports identifiers
90;; enclosed within brackets [].
90 91
91;; Add better hilight support for other brands; there is a bias towards 92;; ChangeLog available on request.
92;; Oracle because that's what I use at work. Anybody else just send in
93;; your lists of reserved words, keywords and builtin functions! As
94;; long as I don't receive any feedback, everything is hilighted with
95;; ANSI keywords only. I received the list of ANSI keywords from a
96;; user; if you know of any changes, let me know.
97 93
98;; Add different hilighting levels. 94;;; Product Support:
95
96;; Set the variable `sql-product' to the product you usually use. If
97;; you occasionally use another product, for certain files, add a
98;; comment on the first line of the file saying
99;; -*- sql-product: mysql -*-
100;; See section "File Variables" in the Emacs manual for more info.
101
102;;; Adding another product:
103
104;; To add support for additional SQL products the following steps
105;; must be followed ("xyz" is the name of the product in the examples
106;; below):
107
108;; 1) Add the product to `sql-product' choice list.
109
110;; (const :tag "XyzDB" xyz)
111
112;; 2) Add an entry to the `sql-product-support' list.
113
114;; (xyz
115;; :font-lock sql-mode-xyz-font-lock-keywords
116;; :sqli-login (user password server database)
117;; :sqli-connect sql-connect-xyz
118;; :sqli-prompt-regexp "^xyzdb> "
119;; :sqli-prompt-length 7
120;; :sqli-input-sender nil
121;; :syntax-alist ((?# . "w")))
122
123;; 3) Add customizable values for the product interpreter and options.
124
125;; ;; Customization for XyzDB
126;;
127;; (defcustom sql-xyz-program "ixyz"
128;; "*Command to start ixyz by XyzDB."
129;; :type 'file
130;; :group 'SQL)
131;;
132;; (defcustom sql-xyz-options '("-X" "-Y" "-Z")
133;; "*List of additional options for `sql-xyz-program'."
134;; :type '(repeat string)
135;; :group 'SQL)
136
137;; 4) Add an entry to SQL->Product submenu.
138
139;; ["XyzDB" sql-highlight-xyz-keywords
140;; :style radio
141;; :selected (eq sql-product 'xyz)]
142
143;; 5) Add the font-lock specifications. At a minimum, default to
144;; using ANSI keywords. See sql-mode-oracle-font-lock-keywords for
145;; a more complex example.
146
147;; (defvar sql-mode-xyz-font-lock-keywords sql-mode-ansi-font-lock-keywords
148;; "XyzDB SQL keywords used by font-lock.")
149
150;; 6) Add a product highlighting function.
151
152;; (defun sql-highlight-xyz-keywords ()
153;; "Highlight XyzDB keywords."
154;; (interactive)
155;; (sql-set-product 'xyz))
156
157;; 7) Add an autoloaded SQLi function.
158
159;; ;;;###autoload
160;; (defun sql-xyz ()
161;; "Run ixyz by XyzDB as an inferior process."
162;; (interactive)
163;; (sql-product-interactive 'xyz))
164
165;; 8) Add a connect function which formats the command line arguments
166;; and starts the product interpreter in a comint buffer. See the
167;; existing connect functions for examples of the types of
168;; processing available.
169
170;; (defun sql-connect-xyz ()
171;; "Create comint buffer and connect to XyzDB using the login
172;; parameters and command options."
173;;
174;; ;; Do something with `sql-user', `sql-password',
175;; ;; `sql-database', and `sql-server'.
176;; (let ((params sql-xyz-options))
177;; (if (not (string= "" sql-server))
178;; (setq params (append (list "-S" sql-server) params)))
179;; (if (not (string= "" sql-database))
180;; (setq params (append (list "-D" sql-database) params)))
181;; (if (not (string= "" sql-password))
182;; (setq params (append (list "-P" sql-password) params)))
183;; (if (not (string= "" sql-user))
184;; (setq params (append (list "-U" sql-user) params)))
185;; (set-buffer (apply 'make-comint "SQL" sql-xyz-program
186;; nil params))))
187
188;; 9) Save and compile sql.el.
99 189
100;;; Thanks to all the people who helped me out: 190;;; Thanks to all the people who helped me out:
101 191
@@ -105,6 +195,7 @@
105;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> 195;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
106;; nino <nino@inform.dk> 196;; nino <nino@inform.dk>
107;; Berend de Boer <berend@pobox.com> 197;; Berend de Boer <berend@pobox.com>
198;; Michael Mauger <mmaug@yahoo.com>
108 199
109 200
110 201
@@ -112,7 +203,8 @@
112 203
113(require 'comint) 204(require 'comint)
114;; Need the following to allow GNU Emacs 19 to compile the file. 205;; Need the following to allow GNU Emacs 19 to compile the file.
115(require 'regexp-opt) 206(eval-when-compile
207 (require 'regexp-opt))
116(require 'custom) 208(require 'custom)
117 209
118;;; Allow customization 210;;; Allow customization
@@ -122,7 +214,7 @@
122 :version "20.4" 214 :version "20.4"
123 :group 'processes) 215 :group 'processes)
124 216
125;; These three variables will be used as defaults, if set. 217;; These four variables will be used as defaults, if set.
126 218
127(defcustom sql-user "" 219(defcustom sql-user ""
128 "*Default username." 220 "*Default username."
@@ -147,6 +239,145 @@ Customizing your password will store it in your ~/.emacs file."
147 :type 'string 239 :type 'string
148 :group 'SQL) 240 :group 'SQL)
149 241
242;; SQL Product support
243(defcustom sql-product 'ansi
244 "*Select the SQL database product used so that buffers can be
245highlighted properly when you open them."
246 :type '(choice (const :tag "ANSI" ansi)
247 (const :tag "DB2" db2)
248 (const :tag "Informix" informix)
249 (const :tag "Ingres" ingres)
250 (const :tag "Interbase" interbase)
251 (const :tag "Linter" linter)
252 (const :tag "Microsoft" ms)
253 (const :tag "MySQL" mysql)
254 (const :tag "Oracle" oracle)
255 (const :tag "PostGres" postgres)
256 (const :tag "Solid" solid)
257 (const :tag "SQLite" sqlite)
258 (const :tag "Sybase" sybase))
259 :group 'SQL)
260
261(defvar sql-interactive-product nil
262 "Product under `sql-interactive-mode'.")
263
264(defvar sql-product-support
265 '((ansi
266 :font-lock sql-mode-ansi-font-lock-keywords)
267 (db2
268 :font-lock sql-mode-db2-font-lock-keywords
269 :sqli-login nil
270 :sqli-connect sql-connect-db2
271 :sqli-prompt-regexp "^db2 => "
272 :sqli-prompt-length 7)
273 (informix
274 :font-lock sql-mode-informix-font-lock-keywords
275 :sqli-login (database)
276 :sqli-connect sql-connect-informix
277 :sqli-prompt-regexp "^SQL> "
278 :sqli-prompt-length 5)
279 (ingres
280 :font-lock sql-mode-ingres-font-lock-keywords
281 :sqli-login (database)
282 :sqli-connect sql-connect-ingres
283 :sqli-prompt-regexp "^\* "
284 :sqli-prompt-length 2)
285 (interbase
286 :font-lock sql-mode-interbase-font-lock-keywords
287 :sqli-login (user password database)
288 :sqli-connect sql-connect-interbase
289 :sqli-prompt-regexp "^SQL> "
290 :sqli-prompt-length 5)
291 (linter
292 :font-lock sql-mode-linter-font-lock-keywords
293 :sqli-login (user password database server)
294 :sqli-connect sql-connect-linter
295 :sqli-prompt-regexp "^SQL>"
296 :sqli-prompt-length 4)
297 (ms
298 :font-lock sql-mode-ms-font-lock-keywords
299 :sqli-login (user password server database)
300 :sqli-connect sql-connect-ms
301 :sqli-prompt-regexp "^[0-9]*>"
302 :sqli-prompt-length 5
303 :syntax-alist ((?@ . "w")))
304 (mysql
305 :font-lock sql-mode-mysql-font-lock-keywords
306 :sqli-login (user password database server)
307 :sqli-connect sql-connect-mysql
308 :sqli-prompt-regexp "^mysql> "
309 :sqli-prompt-length 6)
310 (oracle
311 :font-lock sql-mode-oracle-font-lock-keywords
312 :sqli-login (user password database)
313 :sqli-connect sql-connect-oracle
314 :sqli-prompt-regexp "^SQL> "
315 :sqli-prompt-length 5
316 :syntax-alist ((?$ . "w") (?# . "w")))
317 (postgres
318 :font-lock sql-mode-postgres-font-lock-keywords
319 :sqli-login (database server)
320 :sqli-connect sql-connect-postgres
321 :sqli-prompt-regexp "^.*> *"
322 :sqli-prompt-length 5)
323 (solid
324 :font-lock sql-mode-solid-font-lock-keywords
325 :sqli-login (user password server)
326 :sqli-connect sql-connect-solid
327 :sqli-prompt-regexp "^"
328 :sqli-prompt-length 0)
329 (sqlite
330 :font-lock sql-mode-sqlite-font-lock-keywords
331 :sqli-login (user password server database)
332 :sqli-connect sql-connect-sqlite
333 :sqli-prompt-regexp "^sqlite> "
334 :sqli-prompt-length 8)
335 (sybase
336 :font-lock sql-mode-sybase-font-lock-keywords
337 :sqli-login (server user password database)
338 :sqli-connect sql-connect-sybase
339 :sqli-prompt-regexp "^SQL> "
340 :sqli-prompt-length 5
341 :syntax-alist ((?@ . "w")))
342 )
343 "This variable contains a list of product features for each of the
344SQL products handled by `sql-mode'. Without an entry in this list a
345product will not be properly highlighted and will not support
346`sql-interactive-mode'.
347
348Each element in the list is in the following format:
349
350 \(PRODUCT FEATURE VALUE ...)
351
352where PRODUCT is the appropriate value of `sql-product'. The product
353name is then followed by FEATURE-VALUE pairs. If a FEATURE is not
354specified, its VALUE is treated as nil. FEATURE must be one of the
355following:
356
357 :font-lock name of the variable containing the product
358 specific font lock highlighting patterns.
359
360 :sqli-login a list of login parameters (i.e., user,
361 password, database and server) needed to
362 connect to the database.
363
364 :sqli-connect the name of a function which accepts no
365 parameters that will use the values of
366 `sql-user', `sql-password',
367 `sql-database' and `sql-server' to open a
368 comint buffer and connect to the
369 database. Do product specific
370 configuration of comint in this function.
371
372 :sqli-prompt-regexp a regular expression string that matches the
373 prompt issued by the product interpreter.
374
375 :sqli-prompt-length the length of the prompt on the line.
376
377 :syntax-alist an alist of syntax table entries to enable
378 special character treatment by font-lock and
379 imenu. ")
380
150;; misc customization of sql.el behaviour 381;; misc customization of sql.el behaviour
151 382
152(defcustom sql-electric-stuff nil 383(defcustom sql-electric-stuff nil
@@ -177,8 +408,15 @@ buffer is shown using `display-buffer'."
177;; imenu support for sql-mode. 408;; imenu support for sql-mode.
178 409
179(defvar sql-imenu-generic-expression 410(defvar sql-imenu-generic-expression
180 '(("Tables" "^\\s-*create\\s-+table\\s-+\\(\\w+\\)" 1) 411 ;; Items are in reverse order because they are rendered in reverse.
181 ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1)) 412 '(("Rules/Defaults" "^\\s-*create\\s-+\\(rule\\|default\\)\\s-+\\(\\w+\\)" 2)
413 ("Sequences" "^\\s-*create\\s-+sequence\\s-+\\(\\w+\\)" 1)
414 ("Triggers" "^\\s-*\\(create\\s-+\\(or\\s-+replace\\s-+\\)?\\)?trigger\\s-+\\(\\w+\\)" 3)
415 ("Functions" "^\\s-*\\(create\\s-+\\(or\\s-+replace\\s-+\\)?\\)?function\\s-+\\(\\w+\\)" 3)
416 ("Procedures" "^\\s-*\\(create\\s-+\\(or\\s-+replace\\s-+\\)?\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4)
417 ("Packages" "^\\s-*create\\s-+\\(or\\s-+replace\\s-+\\)?package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3)
418 ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1)
419 ("Tables/Views" "^\\s-*create\\s-+\\(\\(global\\s-+\\)?\\(temporary\\s-+\\)?table\\|view\\)\\s-+\\(\\w+\\)" 4))
182 "Define interesting points in the SQL buffer for `imenu'. 420 "Define interesting points in the SQL buffer for `imenu'.
183 421
184This is used to set `imenu-generic-expression' when SQL mode is 422This is used to set `imenu-generic-expression' when SQL mode is
@@ -274,7 +512,7 @@ The program can also specify a TCP connection. See `make-comint'."
274 :group 'SQL) 512 :group 'SQL)
275 513
276(defcustom sql-sqlite-options nil 514(defcustom sql-sqlite-options nil
277 "*List of additional options for `sql-mysql-program'. 515 "*List of additional options for `sql-sqlite-program'.
278The following list of options is reported to make things work 516The following list of options is reported to make things work
279on Windows: \"-C\" \"-t\" \"-f\" \"-n\"." 517on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
280 :type '(repeat string) 518 :type '(repeat string)
@@ -353,8 +591,8 @@ The program can also specify a TCP connection. See `make-comint'."
353 591
354;; Customization for Microsoft 592;; Customization for Microsoft
355 593
356(defcustom sql-ms-program "isql" 594(defcustom sql-ms-program "osql"
357 "*Command to start isql by Microsoft. 595 "*Command to start osql by Microsoft.
358 596
359Starts `sql-interactive-mode' after doing some setup. 597Starts `sql-interactive-mode' after doing some setup.
360 598
@@ -468,12 +706,12 @@ the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
468(defvar sql-prompt-regexp nil 706(defvar sql-prompt-regexp nil
469 "Prompt used to initialize `comint-prompt-regexp'. 707 "Prompt used to initialize `comint-prompt-regexp'.
470 708
471You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.") 709You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.")
472 710
473(defvar sql-prompt-length 0 711(defvar sql-prompt-length 0
474 "Prompt used to set `left-margin' in `sql-interactive-mode'. 712 "Prompt used to set `left-margin' in `sql-interactive-mode'.
475 713
476You can change it on `sql-interactive-mode-hook'.") 714You can change `sql-prompt-length' on `sql-interactive-mode-hook'.")
477 715
478(defvar sql-alternate-buffer-name nil 716(defvar sql-alternate-buffer-name nil
479 "Buffer-local string used to possibly rename the SQLi buffer. 717 "Buffer-local string used to possibly rename the SQLi buffer.
@@ -518,22 +756,60 @@ Based on `comint-mode-map'.")
518 (get-buffer-process sql-buffer))] 756 (get-buffer-process sql-buffer))]
519 ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs 757 ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs
520 mark-active) 758 mark-active)
521 (mark)); XEmacs 759 (mark t)); XEmacs
522 (buffer-live-p sql-buffer) 760 (buffer-live-p sql-buffer)
523 (get-buffer-process sql-buffer))] 761 (get-buffer-process sql-buffer))]
524 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) 762 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)
525 (get-buffer-process sql-buffer))] 763 (get-buffer-process sql-buffer))]
764 ["--" nil nil]
765 ["Start SQLi session" sql-product-interactive (sql-product-feature :sqli-connect)]
526 ["Show SQLi buffer" sql-show-sqli-buffer t] 766 ["Show SQLi buffer" sql-show-sqli-buffer t]
527 ["Set SQLi buffer" sql-set-sqli-buffer t] 767 ["Set SQLi buffer" sql-set-sqli-buffer t]
528 ["Pop to SQLi buffer after send" 768 ["Pop to SQLi buffer after send"
529 sql-toggle-pop-to-buffer-after-send-region 769 sql-toggle-pop-to-buffer-after-send-region
530 :style toggle 770 :style toggle
531 :selected sql-pop-to-buffer-after-send-region] 771 :selected sql-pop-to-buffer-after-send-region]
532 ("Highlighting" 772 ["--" nil nil]
533 ["ANSI SQL keywords" sql-highlight-ansi-keywords t] 773 ("Product"
534 ["Oracle keywords" sql-highlight-oracle-keywords t] 774 ["ANSI" sql-highlight-ansi-keywords
535 ["Postgres keywords" sql-highlight-postgres-keywords t] 775 :style radio
536 ["Linter keywords" sql-highlight-linter-keywords t] 776 :selected (eq sql-product 'ansi)]
777 ["DB2" sql-highlight-db2-keywords
778 :style radio
779 :selected (eq sql-product 'db2)]
780 ["Informix" sql-highlight-informix-keywords
781 :style radio
782 :selected (eq sql-product 'informix)]
783 ["Ingres" sql-highlight-ingres-keywords
784 :style radio
785 :selected (eq sql-product 'ingres)]
786 ["Interbase" sql-highlight-interbase-keywords
787 :style radio
788 :selected (eq sql-product 'interbase)]
789 ["Linter" sql-highlight-linter-keywords
790 :style radio
791 :selected (eq sql-product 'linter)]
792 ["Microsoft" sql-highlight-ms-keywords
793 :style radio
794 :selected (eq sql-product 'ms)]
795 ["MySQL" sql-highlight-mysql-keywords
796 :style radio
797 :selected (eq sql-product 'mysql)]
798 ["Oracle" sql-highlight-oracle-keywords
799 :style radio
800 :selected (eq sql-product 'oracle)]
801 ["Postgres" sql-highlight-postgres-keywords
802 :style radio
803 :selected (eq sql-product 'postgres)]
804 ["Solid" sql-highlight-solid-keywords
805 :style radio
806 :selected (eq sql-product 'solid)]
807 ["SQLite" sql-highlight-sqlite-keywords
808 :style radio
809 :selected (eq sql-product 'sqlite)]
810 ["Sybase" sql-highlight-sybase-keywords
811 :style radio
812 :selected (eq sql-product 'sybase)]
537 ))) 813 )))
538 814
539;; easy menu for sql-interactive-mode. 815;; easy menu for sql-interactive-mode.
@@ -551,12 +827,22 @@ Based on `comint-mode-map'.")
551 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.") 827 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")
552(if sql-mode-abbrev-table 828(if sql-mode-abbrev-table
553 () 829 ()
554 (let ((wrapper)) 830 (let ((nargs (cdr (subr-arity (symbol-function 'define-abbrev))))
555 (define-abbrev-table 'sql-mode-abbrev-table ()) 831 d-a)
556 (define-abbrev sql-mode-abbrev-table "ins" "insert") 832 ;; In Emacs 21.3+, provide SYSTEM-FLAG to define-abbrev.
557 (define-abbrev sql-mode-abbrev-table "upd" "update") 833 (setq d-a
558 (define-abbrev sql-mode-abbrev-table "del" "delete") 834 (if (>= nargs 6)
559 (define-abbrev sql-mode-abbrev-table "sel" "select"))) 835 '(lambda (name expansion) (define-abbrev sql-mode-abbrev-table name expansion nil 0 t))
836 '(lambda (name expansion) (define-abbrev sql-mode-abbrev-table name expansion))))
837
838 (define-abbrev-table 'sql-mode-abbrev-table nil)
839 (funcall d-a "ins" "insert")
840 (funcall d-a "upd" "update")
841 (funcall d-a "del" "delete")
842 (funcall d-a "sel" "select")
843 (funcall d-a "proc" "procedure")
844 (funcall d-a "func" "function")
845 (funcall d-a "cr" "create")))
560 846
561;; Syntax Table 847;; Syntax Table
562 848
@@ -581,146 +867,253 @@ Based on `comint-mode-map'.")
581 867
582;; Font lock support 868;; Font lock support
583 869
584(defvar sql-mode-ansi-font-lock-keywords nil 870(defvar sql-mode-font-lock-object-name
585 "ANSI SQL keywords used by font-lock. 871 (list (concat "^\\s-*\\(create\\(\\s-+or\\s-+replace\\)?\\|drop\\|alter\\)?\\s-+"
872 "\\(\\(global\\s-+\\)?\\(temporary\\s-+\\)?table\\|view\\|package\\(\\s-+body\\)?\\|"
873 "proc\\(edure\\)?\\|function\\|trigger\\|sequence\\|rule\\|default\\)\\s-+\\(\\w+\\)")
874 8 'font-lock-function-name-face)
586 875
587This variable is used by `sql-mode' and `sql-interactive-mode'. The 876 "Pattern to match the names of top-level objects in a CREATE,
588regular expressions are created during compilation by calling the 877DROP or ALTER statement.
589function `regexp-opt'. Therefore, take a look at the source before 878
590you define your own sql-mode-ansi-font-lock-keywords. You may want to 879The format of variable should be a valid `font-lock-keywords'
591add functions and PL/SQL keywords.") 880entry.")
592(if sql-mode-ansi-font-lock-keywords 881
593 () 882(defvar sql-mode-ansi-font-lock-keywords
594 (let ((ansi-keywords (eval-when-compile 883 (let ((ansi-keywords (eval-when-compile
595 (concat "\\b" 884 (concat "\\b"
596 (regexp-opt '( 885 (regexp-opt '(
886
597"authorization" "avg" "begin" "close" "cobol" "commit" 887"authorization" "avg" "begin" "close" "cobol" "commit"
598"continue" "count" "declare" "double" "end" "escape" 888"continue" "count" "declare" "double" "end" "escape"
599"exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator" 889"exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"
600"key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli" 890"key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli"
601"precision" "primary" "procedure" "references" "rollback" 891"precision" "primary" "procedure" "references" "rollback"
602"schema" "section" "some" "sqlcode" "sqlerror" "sum" "work") t) "\\b"))) 892"schema" "section" "some" "sqlcode" "sqlerror" "sum" "work"
893
894) t) "\\b")))
603 (ansi-reserved-words (eval-when-compile 895 (ansi-reserved-words (eval-when-compile
604 (concat "\\b" 896 (concat "\\b"
605 (regexp-opt '( 897 (regexp-opt '(
898
606"all" "and" "any" "as" "asc" "between" "by" "check" "create" 899"all" "and" "any" "as" "asc" "between" "by" "check" "create"
607"current" "default" "delete" "desc" "distinct" "exists" "float" "for" 900"current" "default" "delete" "desc" "distinct" "exists" "float" "for"
608"from" "grant" "group" "having" "in" "insert" "into" "is" 901"from" "grant" "group" "having" "in" "insert" "into" "is"
609"like" "not" "null" "of" "on" "option" "or" "order" "privileges" 902"like" "not" "null" "of" "on" "option" "or" "order" "privileges"
610"public" "select" "set" "table" "to" "union" "unique" 903"public" "select" "set" "table" "to" "union" "unique"
611"update" "user" "values" "view" "where" "with") t) "\\b"))) 904"update" "user" "values" "view" "where" "with"
905
906) t) "\\b")))
612 (ansi-types (eval-when-compile 907 (ansi-types (eval-when-compile
613 (concat "\\b" 908 (concat "\\b"
614 (regexp-opt '( 909 (regexp-opt '(
910
615;; ANSI Keywords that look like types 911;; ANSI Keywords that look like types
616"character" "cursor" "dec" "int" "real" 912"character" "cursor" "dec" "int" "real"
617;; ANSI Reserved Word that look like types 913;; ANSI Reserved Word that look like types
618"char" "integer" "smallint" ) t) "\\b")))) 914"char" "integer" "smallint"
619 (setq sql-mode-ansi-font-lock-keywords 915
620 (list (cons ansi-keywords 'font-lock-function-name-face) 916) t) "\\b"))))
917 (list (cons ansi-keywords 'font-lock-keyword-face)
621 (cons ansi-reserved-words 'font-lock-keyword-face) 918 (cons ansi-reserved-words 'font-lock-keyword-face)
622 (cons ansi-types 'font-lock-type-face))))) 919 (cons ansi-types 'font-lock-type-face)))
623 920
624(defvar sql-mode-oracle-font-lock-keywords nil 921 "ANSI SQL keywords used by font-lock.
625 "Oracle SQL keywords used by font-lock.
626 922
627This variable is used by `sql-mode' and `sql-interactive-mode'. The 923This variable is used by `sql-mode' and `sql-interactive-mode'. The
628regular expressions are created during compilation by calling the 924regular expressions are created during compilation by calling the
629function `regexp-opt'. Therefore, take a look at the source before 925function `regexp-opt'. Therefore, take a look at the source before
630you define your own sql-mode-oracle-font-lock-keywords. You may want 926you define your own sql-mode-ansi-font-lock-keywords. You may want to
631to add functions and PL/SQL keywords.") 927add functions and PL/SQL keywords.")
632(if sql-mode-oracle-font-lock-keywords 928
633 () 929(defvar sql-mode-oracle-font-lock-keywords
634 (let ((oracle-keywords (eval-when-compile 930 (let ((oracle-keywords (eval-when-compile
635 (concat "\\b" 931 (concat "\\b"
636 (regexp-opt '( 932 (regexp-opt '(
637"admin" "after" "allocate" "analyze" "archive" "archivelog" "backup" 933;; Oracle (+ANSI) SQL keywords
638"become" "before" "block" "body" "cache" "cancel" "cascade" "change" 934
639"checkpoint" "compile" "constraint" "constraints" "contents" 935; ANSI keywords
640"controlfile" "cycle" "database" "datafile" "dba" "disable" "dismount" 936"authorization" "avg" "begin" "close" "cobol" "commit"
641"dump" "each" "else" "elsif" "enable" "events" "except" "exceptions" 937"continue" "count" "declare" "double" "end" "escape"
642"execute" "exit" "explain" "extent" "externally" "false" "flush" "force" 938"exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"
643"freelist" "freelists" "function" "groups" "if" "including" "initrans" 939"key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli"
644"instance" "layer" "link" "lists" "logfile" "loop" "manage" "manual" 940"precision" "primary" "procedure" "references" "rollback"
645"maxdatafiles" "maxinistances" "maxlogfiles" "maxloghistory" 941"schema" "section" "some" "sqlcode" "sqlerror" "sum" "work"
646"maxlogmembers" "maxtrans" "maxvalue" "minextents" "minvalue" "mount" 942
647"new" "next" "noarchivelog" "nocache" "nocycle" "nomaxvalue" 943; ANSI reserved words
648"nominvalue" "none" "noorder" "noresetlogs" "normal" "nosort" "off" 944"all" "and" "any" "as" "asc" "between" "by" "check" "create"
649"old" "only" "optimal" "others" "out" "own" "package" "parallel" 945"current" "default" "delete" "desc" "distinct" "exists" "float" "for"
650"pctincrease" "pctused" "plan" "pragma" "private" "profile" "quota" 946"from" "grant" "group" "having" "in" "insert" "into" "is"
651"raise" "read" "recover" "referencing" "resetlogs" "restrict_references" 947"like" "not" "null" "of" "on" "option" "or" "order" "privileges"
652"restricted" "return" "returning" "reuse" "rnds" "rnps" "role" "roles" 948"public" "select" "set" "table" "to" "union" "unique"
653"savepoint" "scn" "segment" "sequence" "shared" "snapshot" "sort" 949"update" "user" "values" "view" "where" "with"
654"statement_id" "statistics" "stop" "storage" "subtype" "switch" "system" 950
655"tables" "tablespace" "temporary" "thread" "time" "tracing" 951"access" "add" "admin" "after" "allocate" "alter" "analyze" "archive"
656"transaction" "triggers" "true" "truncate" "type" "under" "unlimited" 952"archivelog" "audit" "authid" "backup" "become" "before" "block"
657"until" "use" "using" "when" "while" "wnds" "wnps" "write") t) "\\b"))) 953"body" "cache" "cancel" "cascade" "change" "checkpoint" "cluster"
954"comment" "compile" "compress" "compute" "connect" "constraint"
955"constraints" "contents" "controlfile" "cross" "currval" "cycle"
956"database" "datafile" "dba" "deterministic" "disable" "dismount"
957"drop" "dump" "each" "else" "else" "elsif" "enable" "events" "except"
958"exceptions" "exclusive" "execute" "exit" "explain" "extent"
959"externally" "false" "file" "flush" "force" "freelist" "freelists"
960"full" "function" "global" "grant" "groups" "identified" "if"
961"immediate" "including" "increment" "index" "initial" "initrans"
962"inner" "instance" "intersect" "join" "layer" "left" "level" "link"
963"lists" "lock" "logfile" "long" "loop" "manage" "manual"
964"maxdatafiles" "maxextents" "maxinistances" "maxlogfiles"
965"maxloghistory" "maxlogmembers" "maxtrans" "maxvalue" "merge"
966"minextents" "minus" "minvalue" "mode" "modify" "mount" "natural"
967"new" "next" "nextval" "noarchivelog" "noaudit" "nocache" "nocompress"
968"nocycle" "nomaxvalue" "nominvalue" "none" "noorder" "noresetlogs"
969"normal" "nosort" "nowait" "off" "offline" "old" "online" "only"
970"optimal" "others" "out" "outer" "over" "own" "package" "parallel"
971"parallel_enable" "pctfree" "pctincrease" "pctused" "plan" "pragma"
972"preserve" "prior" "private" "profile" "quota" "raise" "raw" "read"
973"recover" "referencing" "rename" "replace" "resetlogs" "resource"
974"restrict_references" "restricted" "return" "returning" "reuse"
975"revoke" "right" "rnds" "rnps" "role" "roles" "row" "rowlabel"
976"rownum" "rows" "savepoint" "scn" "segment" "sequence" "session"
977"share" "shared" "size" "snapshot" "sort" "statement_id" "statistics"
978"stop" "storage" "subtype" "successful" "switch" "synonym" "sysdate"
979"system" "tables" "tablespace" "temporary" "then" "thread" "tracing"
980"transaction" "trigger" "triggers" "true" "truncate" "type" "uid"
981"under" "unlimited" "until" "use" "using" "validate" "when" "while"
982"wnds" "wnps" "write"
983
984) t) "\\b")))
658 (oracle-warning-words (eval-when-compile 985 (oracle-warning-words (eval-when-compile
659 (concat "\\b" 986 (concat "\\b"
660 (regexp-opt '( 987 (regexp-opt '(
661"cursor_already_open" "dup_val_on_index" "exception" "invalid_cursor" 988;; PLSQL defined exceptions
989
990"access_into_null" "case_not_found" "collection_is_null"
991"cursor_already_open" "dup_val_on_index" "invalid_cursor"
662"invalid_number" "login_denied" "no_data_found" "not_logged_on" 992"invalid_number" "login_denied" "no_data_found" "not_logged_on"
663"notfound" "others" "pragma" "program_error" "storage_error" 993"program_error" "rowtype_mismatch" "self_is_null" "storage_error"
664"timeout_on_resource" "too_many_rows" "transaction_backed_out" 994"subscript_beyond_count" "subscript_outside_limit" "sys_invalid_rowid"
665"value_error" "zero_divide") t) "\\b"))) 995"timeout_on_resource" "too_many_rows" "value_error" "zero_divide"
666 (oracle-reserved-words (eval-when-compile 996"exception" "notfound"
667 (concat "\\b" 997
998) t) "\\b")))
999
1000 (oracle-sqlplus-commands
1001 (eval-when-compile
1002 (concat "^\\(\\("
668 (regexp-opt '( 1003 (regexp-opt '(
669"access" "add" "alter" "audit" "cluster" "column" "comment" "compress" 1004;; SQL*Plus commands
670"connect" "drop" "else" "exclusive" "file" "grant" 1005
671"identified" "immediate" "increment" "index" "initial" "intersect" 1006"@" "@@" "accept" "append" "archive" "attribute" "break"
672"level" "lock" "long" "maxextents" "minus" "mode" "modify" "noaudit" 1007"btitle" "change" "clear" "column" "connect" "copy" "define"
673"nocompress" "nowait" "number" "offline" "online" "pctfree" "prior" 1008"del" "describe" "disconnect" "edit" "execute" "exit" "get" "help"
674"raw" "rename" "resource" "revoke" "row" "rowlabel" "rownum" 1009"host" "input" "list" "password" "pause" "print" "prompt" "recover"
675"rows" "session" "share" "size" "start" "successful" "synonym" "sysdate" 1010"remark" "repfooter" "repheader" "run" "save" "show" "shutdown"
676"then" "trigger" "uid" "validate" "whenever") t) "\\b"))) 1011"spool" "start" "startup" "store" "timing" "ttitle" "undefine"
677 (oracle-types (eval-when-compile 1012"variable" "whenever"
1013
1014) t)
1015
1016 "\\)\\|"
1017 "\\(compute\\s-+\\(avg\\|cou\\|min\\|max\\|num\\|sum\\|std\\|var\\)\\)\\|"
1018 "\\(set\\s-+\\(appi\\(nfo\\)?\\|array\\(size\\)?\\|"
1019 "auto\\(commit\\)?\\|autop\\(rint\\)?\\|autorecovery\\|"
1020 "autot\\(race\\)?\\|blo\\(ckterminator\\)?\\|cmds\\(ep\\)?\\|"
1021 "colsep\\|com\\(patibility\\)?\\|con\\(cat\\)?\\|"
1022 "copyc\\(ommit\\)?\\|copytypecheck\\|def\\(ine\\)?\\|"
1023 "describe\\|echo\\|editf\\(ile\\)?\\|emb\\(edded\\)?\\|"
1024 "esc\\(ape\\)?\\|feed\\(back\\)?\\|flagger\\|"
1025 "flu\\(sh\\)?\\|hea\\(ding\\)?\\|heads\\(ep\\)?\\|"
1026 "instance\\|lin\\(esize\\)?\\|lobof\\(fset\\)?\\|"
1027 "logsource\\|long\\|longc\\(hunksize\\)?\\|mark\\(up\\)?\\|"
1028 "newp\\(age\\)?\\|null\\|numf\\(ormat\\)?\\|"
1029 "num\\(width\\)?\\|pages\\(ize\\)?\\|pau\\(se\\)?\\|"
1030 "recsep\\|recsepchar\\|serverout\\(put\\)?\\|"
1031 "shift\\(inout\\)?\\|show\\(mode\\)?\\|"
1032 "sqlbl\\(anklines\\)?\\|sqlc\\(ase\\)?\\|"
1033 "sqlco\\(ntinue\\)?\\|sqln\\(umber\\)?\\|"
1034 "sqlpluscompat\\(ibility\\)?\\|sqlpre\\(fix\\)?\\|"
1035 "sqlp\\(rompt\\)?\\|sqlt\\(erminator\\)?\\|"
1036 "suf\\(fix\\)?\\|tab\\|term\\(out\\)?\\|ti\\(me\\)?\\|"
1037 "timi\\(ng\\)?\\|trim\\(out\\)?\\|trims\\(pool\\)?\\|"
1038 "und\\(erline\\)?\\|ver\\(ify\\)?\\|wra\\(p\\)?\\)\\)\\)"
1039 "\\b.*$"
1040 )))
1041
1042 (oracle-types
1043 (eval-when-compile
678 (concat "\\b" 1044 (concat "\\b"
679 (regexp-opt '( 1045 (regexp-opt '(
680;; Oracle Keywords that look like types 1046;; Oracle Keywords that look like types
681;; Oracle Reserved Words that look like types 1047;; Oracle Reserved Words that look like types
682"binary_integer" "blob" "boolean" "constant" "date" "decimal" "rowid" 1048
683"varchar" "varchar2") t) "\\b"))) 1049"bfile" "binary_integer" "blob" "boolean" "byte" "char" "character"
1050"clob" "date" "day" "dec" "decimal" "double" "float" "int" "integer"
1051"interval" "local" "long" "month" "natural" "naturaln" "nchar" "nclob"
1052"number" "numeric" "nvarchar2" "pls_integer" "positive" "positiven"
1053"precision" "raw" "real" "rowid" "second" "signtype" "smallint"
1054"string" "time" "timestamp" "urowid" "varchar" "varchar2" "year"
1055"zone"
1056
1057) t) "\\b")))
684 (oracle-builtin-functions (eval-when-compile 1058 (oracle-builtin-functions (eval-when-compile
685 (concat "\\b" 1059 (concat "\\b"
686 (regexp-opt '( 1060 (regexp-opt '(
687;; Misc Oracle builtin functions 1061;; Misc Oracle builtin functions
688"abs" "add_months" "ascii" "avg" "ceil" "chartorowid" "chr" "concat" 1062
689"convert" "cos" "cosh" "count" "currval" "decode" "dump" "exp" "floor" 1063"abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2"
690"glb" "greatest" "greatest_lb" "hextoraw" "initcap" "instr" "instrb" 1064"avg" "bfilename" "bin_to_num" "bitand" "case" "cast" "ceil"
691"last_day" "least" "least_ub" "length" "lengthb" "ln" "log" "lower" 1065"chartorowid" "chr" "coalesce" "compose" "concat" "convert" "corr"
692"lpad" "ltrim" "lub" "max" "min" "mod" "months_between" "new_time" 1066"cos" "cosh" "count" "covar_pop" "covar_samp" "cume_dist"
693"next_day" "nextval" "nls_initcap" "nls_lower" "nls_upper" "nlssort" 1067"current_date" "current_timestamp" "current_user" "dbtimezone"
694"nvl" "power" "rawtohex" "replace" "round" "rowidtochar" "rpad" 1068"decode" "decompose" "dense_rank" "depth" "deref" "dump" "empty_blob"
695"rtrim" "sign" "sin" "sinh" "soundex" "sqlcode" "sqlerrm" "sqrt" 1069"empty_clob" "existsnode" "exp" "extract" "extractvalue" "first"
696"stddev" "sum" "substr" "substrb" "tan" "tanh" "to_char" 1070"first_value" "floor" "from_tz" "greatest" "group_id" "grouping"
697"to_date" "to_label" "to_multi_byte" "to_number" "to_single_byte" 1071"grouping_id" "hextoraw" "initcap" "instr" "lag" "last" "last_day"
698"translate" "trim" "trunc" "uid" "upper" "userenv" "variance" "vsize") t) "\\b")))) 1072"last_value" "lead" "least" "length" "ln" "localtimestamp" "log"
699 (setq sql-mode-oracle-font-lock-keywords 1073"lower" "lpad" "ltrim" "make_ref" "max" "min" "mod" "months_between"
700 (append sql-mode-ansi-font-lock-keywords 1074"nchr" "new_time" "next_day" "nls_charset_decl_len" "nls_charset_id"
701 (list (cons oracle-keywords 'font-lock-function-name-face) 1075"nls_charset_name" "nls_initcap" "nls_lower" "nlssort" "nls_upper"
1076"ntile" "nullif" "numtodsinterval" "numtoyminterval" "nvl" "nvl2"
1077"path" "percent_rank" "percentile_cont" "percentile_disc" "power"
1078"rank" "ratio_to_report" "rawtohex" "rawtonhex" "ref" "reftohex"
1079"regr_slope" "regr_intercept" "regr_count" "regr_r2" "regr_avgx"
1080"regr_avgy" "regr_sxx" "regr_syy" "regr_sxy" "round"
1081"row_number" "rowidtochar" "rowidtonchar" "rpad" "rtrim"
1082"sessiontimezone" "sign" "sin" "sinh" "soundex" "sqrt" "stddev"
1083"stddev_pop" "stddev_samp" "substr" "sum" "sys_connect_by_path"
1084"sys_context" "sys_dburigen" "sys_extract_utc" "sys_guid" "sys_typeid"
1085"sys_xmlagg" "sys_xmlgen" "sysdate" "systimestamp" "tan" "tanh"
1086"to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte"
1087"to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp"
1088"to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc"
1089"tz_offset" "uid" "unistr" "updatexml" "upper" "user" "userenv"
1090"value" "var_pop" "var_samp" "variance" "vsize" "width_bucket"
1091"xmlagg" "xmlcolattval" "xmlconcat" "xmlelement" "xmlforest"
1092"xmlsequence" "xmltransform"
1093
1094) t) "\\b"))))
1095 (list (cons oracle-sqlplus-commands 'font-lock-doc-face)
1096 (cons oracle-keywords 'font-lock-keyword-face)
702 (cons oracle-warning-words 'font-lock-warning-face) 1097 (cons oracle-warning-words 'font-lock-warning-face)
703 (cons oracle-reserved-words 'font-lock-keyword-face)
704 ;; XEmacs doesn't have font-lock-builtin-face 1098 ;; XEmacs doesn't have font-lock-builtin-face
705 (if (string-match "XEmacs\\|Lucid" emacs-version) 1099 (if (string-match "XEmacs\\|Lucid" emacs-version)
706 (cons oracle-builtin-functions 'font-lock-preprocessor-face) 1100 (cons oracle-builtin-functions 'font-lock-preprocessor-face)
707 ;; GNU Emacs 19 doesn't have it either 1101 ;; GNU Emacs 19 doesn't have it either
708 (if (string-match "GNU Emacs 19" emacs-version) 1102 (if (string-match "GNU Emacs 19" emacs-version)
709 (cons oracle-builtin-functions 'font-lock-function-name-face) 1103 (cons oracle-builtin-functions 'font-lock-keyword-face)
710 ;; Emacs 1104 ;; Emacs
711 (cons oracle-builtin-functions 'font-lock-builtin-face))) 1105 (cons oracle-builtin-functions 'font-lock-builtin-face)))
712 (cons oracle-types 'font-lock-type-face)))))) 1106 (cons oracle-types 'font-lock-type-face)))
713 1107
714(defvar sql-mode-postgres-font-lock-keywords nil 1108 "Oracle SQL keywords used by font-lock.
715 "Postgres SQL keywords used by font-lock.
716 1109
717This variable is used by `sql-mode' and `sql-interactive-mode'. The 1110This variable is used by `sql-mode' and `sql-interactive-mode'. The
718regular expressions are created during compilation by calling the 1111regular expressions are created during compilation by calling the
719function `regexp-opt'. Therefore, take a look at the source before 1112function `regexp-opt'. Therefore, take a look at the source before
720you define your own sql-mode-postgres-font-lock-keywords.") 1113you define your own sql-mode-oracle-font-lock-keywords. You may want
1114to add functions and PL/SQL keywords.")
721 1115
722(if sql-mode-postgres-font-lock-keywords 1116(defvar sql-mode-postgres-font-lock-keywords
723 ()
724 (let ((postgres-reserved-words (eval-when-compile 1117 (let ((postgres-reserved-words (eval-when-compile
725 (concat "\\b" 1118 (concat "\\b"
726 (regexp-opt '( 1119 (regexp-opt '(
@@ -729,14 +1122,17 @@ you define your own sql-mode-postgres-font-lock-keywords.")
729 (postgres-types (eval-when-compile 1122 (postgres-types (eval-when-compile
730 (concat "\\b" 1123 (concat "\\b"
731 (regexp-opt '( 1124 (regexp-opt '(
1125
732"bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date" 1126"bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date"
733"float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path" 1127"float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path"
734"point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar" 1128"point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar"
1129
735) t)"\\b"))) 1130) t)"\\b")))
736 (postgres-builtin-functions (eval-when-compile 1131 (postgres-builtin-functions (eval-when-compile
737 (concat "\\b" 1132 (concat "\\b"
738 (regexp-opt '( 1133 (regexp-opt '(
739;; Misc Postgres builtin functions 1134;; Misc Postgres builtin functions
1135
740"abstime" "age" "area" "box" "center" "date_part" "date_trunc" 1136"abstime" "age" "area" "box" "center" "date_part" "date_trunc"
741"datetime" "dexp" "diameter" "dpow" "float" "float4" "height" 1137"datetime" "dexp" "diameter" "dpow" "float" "float4" "height"
742"initcap" "integer" "isclosed" "isfinite" "isoldpath" "isopen" 1138"initcap" "integer" "isclosed" "isfinite" "isoldpath" "isopen"
@@ -744,8 +1140,8 @@ you define your own sql-mode-postgres-font-lock-keywords.")
744"position" "radius" "reltime" "revertpoly" "rpad" "rtrim" "substr" 1140"position" "radius" "reltime" "revertpoly" "rpad" "rtrim" "substr"
745"substring" "text" "timespan" "translate" "trim" "upgradepath" 1141"substring" "text" "timespan" "translate" "trim" "upgradepath"
746"upgradepoly" "upper" "varchar" "width" 1142"upgradepoly" "upper" "varchar" "width"
1143
747) t) "\\b")))) 1144) t) "\\b"))))
748 (setq sql-mode-postgres-font-lock-keywords
749 (append sql-mode-ansi-font-lock-keywords 1145 (append sql-mode-ansi-font-lock-keywords
750 (list (cons postgres-reserved-words 'font-lock-keyword-face) 1146 (list (cons postgres-reserved-words 'font-lock-keyword-face)
751 ;; XEmacs doesn't have 'font-lock-builtin-face 1147 ;; XEmacs doesn't have 'font-lock-builtin-face
@@ -753,21 +1149,20 @@ you define your own sql-mode-postgres-font-lock-keywords.")
753 (cons postgres-builtin-functions 'font-lock-preprocessor-face) 1149 (cons postgres-builtin-functions 'font-lock-preprocessor-face)
754 ;; Emacs 1150 ;; Emacs
755 (cons postgres-builtin-functions 'font-lock-builtin-face)) 1151 (cons postgres-builtin-functions 'font-lock-builtin-face))
756 (cons postgres-types 'font-lock-type-face)))))) 1152 (cons postgres-types 'font-lock-type-face))))
757
758 1153
759(defvar sql-mode-linter-font-lock-keywords nil 1154 "Postgres SQL keywords used by font-lock.
760 "Linter SQL keywords used by font-lock.
761 1155
762This variable is used by `sql-mode' and `sql-interactive-mode'. The 1156This variable is used by `sql-mode' and `sql-interactive-mode'. The
763regular expressions are created during compilation by calling the 1157regular expressions are created during compilation by calling the
764function `regexp-opt'.") 1158function `regexp-opt'. Therefore, take a look at the source before
1159you define your own sql-mode-postgres-font-lock-keywords.")
765 1160
766(if sql-mode-linter-font-lock-keywords 1161(defvar sql-mode-linter-font-lock-keywords
767 ()
768 (let ((linter-keywords (eval-when-compile 1162 (let ((linter-keywords (eval-when-compile
769 (concat "\\b" 1163 (concat "\\b"
770 (regexp-opt '( 1164 (regexp-opt '(
1165
771"autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel" 1166"autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel"
772"committed" "count" "countblob" "cross" "current" "data" "database" 1167"committed" "count" "countblob" "cross" "current" "data" "database"
773"datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred" 1168"datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred"
@@ -792,10 +1187,12 @@ function `regexp-opt'.")
792"trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown" 1187"trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown"
793"unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes" 1188"unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes"
794"wait" "windows_code" "workspace" "write" "xml" 1189"wait" "windows_code" "workspace" "write" "xml"
1190
795) t) "\\b"))) 1191) t) "\\b")))
796 (linter-reserved-words (eval-when-compile 1192 (linter-reserved-words (eval-when-compile
797 (concat "\\b" 1193 (concat "\\b"
798 (regexp-opt '( 1194 (regexp-opt '(
1195
799"access" "action" "add" "address" "after" "all" "alter" "always" "and" 1196"access" "action" "add" "address" "after" "all" "alter" "always" "and"
800"any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit" 1197"any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit"
801"aud_obj_name_len" "backup" "base" "before" "between" "blobfile" 1198"aud_obj_name_len" "backup" "base" "before" "between" "blobfile"
@@ -813,18 +1210,22 @@ function `regexp-opt'.")
813"start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then" 1210"start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then"
814"to" "union" "unique" "unlock" "until" "update" "using" "values" 1211"to" "union" "unique" "unlock" "until" "update" "using" "values"
815"view" "when" "where" "with" "without" 1212"view" "when" "where" "with" "without"
1213
816) t) "\\b"))) 1214) t) "\\b")))
817 (linter-types (eval-when-compile 1215 (linter-types (eval-when-compile
818 (concat "\\b" 1216 (concat "\\b"
819 (regexp-opt '( 1217 (regexp-opt '(
1218
820"bigint" "bitmap" "blob" "boolean" "char" "character" "date" 1219"bigint" "bitmap" "blob" "boolean" "char" "character" "date"
821"datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar" 1220"datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar"
822"number" "numeric" "real" "smallint" "varbyte" "varchar" "byte" 1221"number" "numeric" "real" "smallint" "varbyte" "varchar" "byte"
823"cursor" "long" 1222"cursor" "long"
1223
824) t) "\\b"))) 1224) t) "\\b")))
825 (linter-builtin-functions (eval-when-compile 1225 (linter-builtin-functions (eval-when-compile
826 (concat "\\b" 1226 (concat "\\b"
827 (regexp-opt '( 1227 (regexp-opt '(
1228
828"abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime" 1229"abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime"
829"exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw" 1230"exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw"
830"getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log" 1231"getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log"
@@ -835,59 +1236,367 @@ function `regexp-opt'.")
835"to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode" 1236"to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode"
836"substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap" 1237"substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap"
837"instr" "least" "multime" "replace" "width" 1238"instr" "least" "multime" "replace" "width"
1239
838) t) "\\b")))) 1240) t) "\\b"))))
839 (setq sql-mode-linter-font-lock-keywords
840 (append sql-mode-ansi-font-lock-keywords 1241 (append sql-mode-ansi-font-lock-keywords
841 (list (cons linter-keywords 'font-lock-function-name-face) 1242 (list (cons linter-keywords 'font-lock-keywords-face)
842 (cons linter-reserved-words 'font-lock-keyword-face) 1243 (cons linter-reserved-words 'font-lock-keyword-face)
843 ;; XEmacs doesn't have font-lock-builtin-face 1244 ;; XEmacs doesn't have font-lock-builtin-face
844 (if (string-match "XEmacs\\|Lucid" emacs-version) 1245 (if (string-match "XEmacs\\|Lucid" emacs-version)
845 (cons linter-builtin-functions 'font-lock-preprocessor-face) 1246 (cons linter-builtin-functions 'font-lock-preprocessor-face)
846 ;; GNU Emacs 19 doesn't have it either 1247 ;; GNU Emacs 19 doesn't have it either
847 (if (string-match "GNU Emacs 19" emacs-version) 1248 (if (string-match "GNU Emacs 19" emacs-version)
848 (cons linter-builtin-functions 'font-lock-function-name-face) 1249 (cons linter-builtin-functions 'font-lock-keywords-face)
849 ;; Emacs 1250 ;; Emacs
850 (cons linter-builtin-functions 'font-lock-builtin-face))) 1251 (cons linter-builtin-functions 'font-lock-builtin-face)))
851 (cons linter-types 'font-lock-type-face)))))) 1252 (cons linter-types 'font-lock-type-face))))
1253
1254 "Linter SQL keywords used by font-lock.
1255
1256This variable is used by `sql-mode' and `sql-interactive-mode'. The
1257regular expressions are created during compilation by calling the
1258function `regexp-opt'.")
1259
1260(defvar sql-mode-ms-font-lock-keywords
1261 (let ((ms-reserved-words (eval-when-compile
1262 (concat "\\b"
1263 (regexp-opt '(
1264
1265"absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization"
1266"avg" "backup" "begin" "between" "break" "browse" "bulk" "by"
1267"cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce"
1268"column" "commit" "committed" "compute" "confirm" "constraint"
1269"contains" "containstable" "continue" "controlrow" "convert" "count"
1270"create" "cross" "current" "current_date" "current_time"
1271"current_timestamp" "current_user" "database" "deallocate"
1272"declare" "default" "delete" "deny" "desc" "disk" "distinct"
1273"distributed" "double" "drop" "dummy" "dump" "else" "end" "errlvl"
1274"errorexit" "escape" "except" "exec" "execute" "exists" "exit" "fetch"
1275"file" "fillfactor" "first" "floppy" "for" "foreign" "freetext"
1276"freetexttable" "from" "full" "goto" "grant" "group" "having"
1277"holdlock" "identity" "identity_insert" "identitycol" "if" "in"
1278"index" "inner" "insert" "intersect" "into" "is" "isolation" "join"
1279"key" "kill" "last" "left" "level" "like" "lineno" "load" "max" "min"
1280"mirrorexit" "national" "next" "nocheck" "nolock" "nonclustered" "not"
1281"null" "nullif" "of" "off" "offsets" "on" "once" "only" "open"
1282"opendatasource" "openquery" "openrowset" "option" "or" "order"
1283"outer" "output" "over" "paglock" "percent" "perm" "permanent" "pipe"
1284"plan" "precision" "prepare" "primary" "print" "prior" "privileges"
1285"proc" "procedure" "processexit" "public" "raiserror" "read"
1286"readcommitted" "readpast" "readtext" "readuncommitted" "reconfigure"
1287"references" "relative" "repeatable" "repeatableread" "replication"
1288"restore" "restrict" "return" "revoke" "right" "rollback" "rowcount"
1289"rowguidcol" "rowlock" "rule" "save" "schema" "select" "serializable"
1290"session_user" "set" "shutdown" "some" "statistics" "sum"
1291"system_user" "table" "tablock" "tablockx" "tape" "temp" "temporary"
1292"textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate"
1293"tsequal" "uncommitted" "union" "unique" "update" "updatetext"
1294"updlock" "use" "user" "values" "view" "waitfor" "when" "where"
1295"while" "with" "work" "writetext"
1296"collate" "function" "openxml" "returns"
1297
1298) t) "\\b")))
1299 (ms-types (eval-when-compile
1300 (concat "\\b"
1301 (regexp-opt '(
1302
1303"binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal"
1304"double" "float" "image" "int" "integer" "money" "national" "nchar"
1305"ntext" "numeric" "numeric" "nvarchar" "precision" "real"
1306"smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint"
1307"uniqueidentifier" "varbinary" "varchar" "varying"
1308
1309) t) "\\b")))
1310
1311 (ms-vars "\\b@[a-zA-Z0-9_]*\\b")
1312
1313 (ms-builtin-functions (eval-when-compile
1314 (concat "\\b"
1315 (regexp-opt '(
1316;; Misc MS builtin functions
1317
1318"@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts"
1319"@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy"
1320"@@langid" "@@language" "@@lock_timeout" "@@max_connections"
1321"@@max_precision" "@@nestlevel" "@@options" "@@pack_received"
1322"@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount"
1323"@@servername" "@@servicename" "@@spid" "@@textsize" "@@timeticks"
1324"@@total_errors" "@@total_read" "@@total_write" "@@trancount"
1325"@@version" "abs" "acos" "and" "app_name" "ascii" "asin" "atan" "atn2"
1326"avg" "case" "cast" "ceiling" "char" "charindex" "coalesce"
1327"col_length" "col_name" "columnproperty" "containstable" "convert"
1328"cos" "cot" "count" "current_timestamp" "current_user" "cursor_status"
1329"databaseproperty" "datalength" "dateadd" "datediff" "datename"
1330"datepart" "day" "db_id" "db_name" "degrees" "difference" "exp"
1331"file_id" "file_name" "filegroup_id" "filegroup_name"
1332"filegroupproperty" "fileproperty" "floor" "formatmessage"
1333"freetexttable" "fulltextcatalogproperty" "fulltextserviceproperty"
1334"getansinull" "getdate" "grouping" "host_id" "host_name" "ident_incr"
1335"ident_seed" "identity" "index_col" "indexproperty" "is_member"
1336"is_srvrolemember" "isdate" "isnull" "isnumeric" "left" "len" "log"
1337"log10" "lower" "ltrim" "max" "min" "month" "nchar" "newid" "nullif"
1338"object_id" "object_name" "objectproperty" "openquery" "openrowset"
1339"parsename" "patindex" "patindex" "permissions" "pi" "power"
1340"quotename" "radians" "rand" "replace" "replicate" "reverse" "right"
1341"round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt"
1342"square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum"
1343"suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan"
1344"textptr" "textvalid" "typeproperty" "unicode" "upper" "user"
1345"user_id" "user_name" "var" "varp" "year"
1346
1347) t) "\\b")))
1348
1349 (ms-config-commands
1350 (eval-when-compile
1351 (concat "^\\(\\(set\\s-+\\("
1352 (regexp-opt '(
1353
1354"datefirst" "dateformat" "deadlock_priority" "lock_timeout"
1355"concat_null_yields_null" "cursor_close_on_commit"
1356"disable_def_cnst_chk" "fips_flagger" "identity_insert" "language"
1357"offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly"
1358"nocount" "noexec" "numeric_roundabort" "parseonly"
1359"query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults"
1360"ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding"
1361"ansi_warnings" "forceplan" "showplan_all" "showplan_text"
1362"statistics" "implicit_transactions" "remote_proc_transactions"
1363"transaction" "xact_abort"
1364
1365) t)
1366 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$"))))
1367
1368 (list (cons ms-config-commands 'font-lock-doc-face)
1369 (cons ms-reserved-words 'font-lock-keyword-face)
1370 ;; XEmacs doesn't have 'font-lock-builtin-face
1371 (if (string-match "XEmacs\\|Lucid" emacs-version)
1372 (cons ms-builtin-functions 'font-lock-preprocessor-face)
1373 ;; Emacs
1374 (cons ms-builtin-functions 'font-lock-builtin-face))
1375 (cons ms-vars 'font-lock-variable-name-face)
1376 (cons ms-types 'font-lock-type-face)))
1377
1378 "Microsoft SQLServer SQL keywords used by font-lock.
1379
1380This variable is used by `sql-mode' and `sql-interactive-mode'. The
1381regular expressions are created during compilation by calling the
1382function `regexp-opt'. Therefore, take a look at the source before
1383you define your own sql-mode-ms-font-lock-keywords.")
1384
1385(defvar sql-mode-sybase-font-lock-keywords sql-mode-ansi-font-lock-keywords
1386 "Sybase SQL keywords used by font-lock.
1387
1388This variable is used by `sql-mode' and `sql-interactive-mode'. The
1389regular expressions are created during compilation by calling the
1390function `regexp-opt'. Therefore, take a look at the source before
1391you define your own sql-mode-sybase-font-lock-keywords.")
1392
1393(defvar sql-mode-informix-font-lock-keywords sql-mode-ansi-font-lock-keywords
1394 "Informix SQL keywords used by font-lock.
1395
1396This variable is used by `sql-mode' and `sql-interactive-mode'. The
1397regular expressions are created during compilation by calling the
1398function `regexp-opt'. Therefore, take a look at the source before
1399you define your own sql-mode-informix-font-lock-keywords.")
1400
1401(defvar sql-mode-interbase-font-lock-keywords sql-mode-ansi-font-lock-keywords
1402 "Interbase SQL keywords used by font-lock.
1403
1404This variable is used by `sql-mode' and `sql-interactive-mode'. The
1405regular expressions are created during compilation by calling the
1406function `regexp-opt'. Therefore, take a look at the source before
1407you define your own sql-mode-interbase-font-lock-keywords.")
1408
1409(defvar sql-mode-ingres-font-lock-keywords sql-mode-ansi-font-lock-keywords
1410 "Ingres SQL keywords used by font-lock.
1411
1412This variable is used by `sql-mode' and `sql-interactive-mode'. The
1413regular expressions are created during compilation by calling the
1414function `regexp-opt'. Therefore, take a look at the source before
1415you define your own sql-mode-interbase-font-lock-keywords.")
1416
1417(defvar sql-mode-solid-font-lock-keywords sql-mode-ansi-font-lock-keywords
1418 "Solid SQL keywords used by font-lock.
1419
1420This variable is used by `sql-mode' and `sql-interactive-mode'. The
1421regular expressions are created during compilation by calling the
1422function `regexp-opt'. Therefore, take a look at the source before
1423you define your own sql-mode-solid-font-lock-keywords.")
1424
1425(defvar sql-mode-mysql-font-lock-keywords sql-mode-ansi-font-lock-keywords
1426 "MySQL SQL keywords used by font-lock.
1427
1428This variable is used by `sql-mode' and `sql-interactive-mode'. The
1429regular expressions are created during compilation by calling the
1430function `regexp-opt'. Therefore, take a look at the source before
1431you define your own sql-mode-mysql-font-lock-keywords.")
1432
1433(defvar sql-mode-sqlite-font-lock-keywords sql-mode-ansi-font-lock-keywords
1434 "SQLite SQL keywords used by font-lock.
1435
1436This variable is used by `sql-mode' and `sql-interactive-mode'. The
1437regular expressions are created during compilation by calling the
1438function `regexp-opt'. Therefore, take a look at the source before
1439you define your own sql-mode-sqlite-font-lock-keywords.")
1440
1441(defvar sql-mode-db2-font-lock-keywords sql-mode-ansi-font-lock-keywords
1442 "DB2 SQL keywords used by font-lock.
852 1443
853(defvar sql-mode-font-lock-keywords sql-mode-ansi-font-lock-keywords 1444This variable is used by `sql-mode' and `sql-interactive-mode'. The
1445regular expressions are created during compilation by calling the
1446function `regexp-opt'. Therefore, take a look at the source before
1447you define your own sql-mode-db2-font-lock-keywords.")
1448
1449(defvar sql-mode-font-lock-keywords nil
854 "SQL keywords used by font-lock. 1450 "SQL keywords used by font-lock.
855 1451
856This variable defaults to `sql-mode-ansi-font-lock-keywords'. This is 1452Setting this variable directly no longer has any affect. Use
857used for the default `font-lock-defaults' value in `sql-mode'. This 1453`sql-product' and `sql-add-product-keywords' to control the
858can be changed by some entry functions to provide more hilighting.") 1454highlighting rules in sql-mode.")
1455
1456
1457
1458;;; SQL Product support functions
1459
1460(defun sql-product-feature (feature &optional product)
1461 "Lookup `feature' needed to support the current SQL product.
1462
1463See \[sql-product-support] for a list of products and supported features."
1464 (cadr
1465 (memq feature
1466 (assoc (or product sql-product)
1467 sql-product-support))))
1468
1469(defun sql-product-font-lock (keywords-only imenu)
1470 "Sets `font-lock-defaults' and `font-lock-keywords' based on
1471the product-specific keywords and syntax-alists defined in
1472`sql-product-support'."
1473 (let
1474 ;; Get the product-specific syntax-alist.
1475 ((syntax-alist
1476 (append
1477 (sql-product-feature :syntax-alist)
1478 '((?_ . "w") (?. . "w")))))
1479
1480 ;; Get the product-specific keywords.
1481 (setq sql-mode-font-lock-keywords
1482 (append
1483 (eval (sql-product-feature :font-lock))
1484 (list sql-mode-font-lock-object-name)))
1485
1486 ;; Setup font-lock. (What is the minimum we should have to do
1487 ;; here?)
1488 (setq font-lock-set-defaults nil
1489 font-lock-keywords sql-mode-font-lock-keywords
1490 font-lock-defaults (list 'sql-mode-font-lock-keywords
1491 keywords-only t syntax-alist))
1492
1493 ;; Setup imenu; it needs the same syntax-alist.
1494 (when imenu
1495 (setq imenu-syntax-alist syntax-alist))))
1496
1497;;;###autoload
1498(defun sql-add-product-keywords (product keywords)
1499 "Append a `font-lock-keywords' entry to the existing entries defined
1500 for the specified `product'."
1501
1502 (let ((font-lock (sql-product-feature :font-lock product)))
1503 (set font-lock (append (eval font-lock) (list keywords)))))
859 1504
860 1505
861 1506
862;;; Functions to switch highlighting 1507;;; Functions to switch highlighting
863 1508
1509(defun sql-highlight-product ()
1510 "Turns on the appropriate font highlighting for the SQL product
1511selected."
1512
1513 (when (eq major-mode 'sql-mode)
1514 ;; Setup font-lock
1515 (sql-product-font-lock nil t)
1516
1517 ;; Force fontification, if its enabled.
1518 (if font-lock-mode
1519 (font-lock-fontify-buffer))
1520
1521 ;; Set the mode name to include the product.
1522 (setq mode-name (concat "SQL[" (prin1-to-string sql-product) "]"))))
1523
1524(defun sql-set-product (product)
1525 "Set `sql-product' to product and enable appropriate
1526highlighting."
1527 (interactive "SEnter SQL product: ")
1528 (when (not (assoc product sql-product-support))
1529 (error "SQL product %s is not supported; treated as ANSI" product)
1530 (setq product 'ansi))
1531
1532 ;; Save product setting and fontify.
1533 (setq sql-product product)
1534 (sql-highlight-product))
1535
864(defun sql-highlight-oracle-keywords () 1536(defun sql-highlight-oracle-keywords ()
865 "Highlight Oracle keywords. 1537 "Highlight Oracle keywords."
866Basically, this just sets `font-lock-keywords' appropriately."
867 (interactive) 1538 (interactive)
868 (setq font-lock-keywords sql-mode-oracle-font-lock-keywords) 1539 (sql-set-product 'oracle))
869 (font-lock-fontify-buffer))
870 1540
871(defun sql-highlight-postgres-keywords () 1541(defun sql-highlight-postgres-keywords ()
872 "Highlight Postgres keywords. 1542 "Highlight Postgres keywords."
873Basically, this just sets `font-lock-keywords' appropriately."
874 (interactive) 1543 (interactive)
875 (setq font-lock-keywords sql-mode-postgres-font-lock-keywords) 1544 (sql-set-product 'postgres))
876 (font-lock-fontify-buffer))
877 1545
878(defun sql-highlight-linter-keywords () 1546(defun sql-highlight-linter-keywords ()
879 "Highlight LINTER keywords. 1547 "Highlight LINTER keywords."
880Basically, this just sets `font-lock-keywords' appropriately." 1548 (interactive)
1549 (sql-set-product 'linter))
1550
1551(defun sql-highlight-ms-keywords ()
1552 "Highlight Microsoft SQLServer keywords."
881 (interactive) 1553 (interactive)
882 (setq font-lock-keywords sql-mode-linter-font-lock-keywords) 1554 (sql-set-product 'ms))
883 (font-lock-fontify-buffer))
884 1555
885(defun sql-highlight-ansi-keywords () 1556(defun sql-highlight-ansi-keywords ()
886 "Highlight ANSI SQL keywords. 1557 "Highlight ANSI SQL keywords."
887Basically, this just sets `font-lock-keywords' appropriately." 1558 (interactive)
1559 (sql-set-product 'ansi))
1560
1561(defun sql-highlight-sybase-keywords ()
1562 "Highlight Sybase SQL keywords."
1563 (interactive)
1564 (sql-set-product 'sybase))
1565
1566(defun sql-highlight-informix-keywords ()
1567 "Highlight Informix SQL keywords."
1568 (interactive)
1569 (sql-set-product 'informix))
1570
1571(defun sql-highlight-interbase-keywords ()
1572 "Highlight Interbase SQL keywords."
1573 (interactive)
1574 (sql-set-product 'interbase))
1575
1576(defun sql-highlight-ingres-keywords ()
1577 "Highlight Ingres SQL keywords."
1578 (interactive)
1579 (sql-set-product 'ingres))
1580
1581(defun sql-highlight-solid-keywords ()
1582 "Highlight Solid SQL keywords."
1583 (interactive)
1584 (sql-set-product 'solid))
1585
1586(defun sql-highlight-mysql-keywords ()
1587 "Highlight MySQL SQL keywords."
1588 (interactive)
1589 (sql-set-product 'mysql))
1590
1591(defun sql-highlight-sqlite-keywords ()
1592 "Highlight SQLite SQL keywords."
1593 (interactive)
1594 (sql-set-product 'sqlite))
1595
1596(defun sql-highlight-db2-keywords ()
1597 "Highlight DB2 SQL keywords."
888 (interactive) 1598 (interactive)
889 (setq font-lock-keywords sql-mode-ansi-font-lock-keywords) 1599 (sql-set-product 'db2))
890 (font-lock-fontify-buffer))
891 1600
892 1601
893 1602
@@ -953,6 +1662,7 @@ Other non-free SQL implementations are also supported:
953 Sybase: \\[sql-sybase] 1662 Sybase: \\[sql-sybase]
954 Ingres: \\[sql-ingres] 1663 Ingres: \\[sql-ingres]
955 Microsoft: \\[sql-ms] 1664 Microsoft: \\[sql-ms]
1665 DB2: \\[sql-db2]
956 Interbase: \\[sql-interbase] 1666 Interbase: \\[sql-interbase]
957 Linter: \\[sql-linter] 1667 Linter: \\[sql-linter]
958 1668
@@ -999,26 +1709,30 @@ Parameter WHAT is a list of the arguments passed to this function.
999The function asks for the username if WHAT contains symbol `user', for 1709The function asks for the username if WHAT contains symbol `user', for
1000the password if it contains symbol `password', for the server if it 1710the password if it contains symbol `password', for the server if it
1001contains symbol `server', and for the database if it contains symbol 1711contains symbol `server', and for the database if it contains symbol
1002`database'. 1712`database'. The members of WHAT are processed in the order in which
1713they are provided.
1003 1714
1004In order to ask the user for username, password and database, call the 1715In order to ask the user for username, password and database, call the
1005function like this: (sql-get-login 'user 'password 'database)." 1716function like this: (sql-get-login 'user 'password 'database)."
1006 (interactive) 1717 (interactive)
1007 (if (memq 'user what) 1718 (while what
1719 (cond
1720 ((eq (car what) 'user) ; user
1008 (setq sql-user 1721 (setq sql-user
1009 (read-from-minibuffer "User: " sql-user nil nil 1722 (read-from-minibuffer "User: " sql-user nil nil
1010 sql-user-history))) 1723 sql-user-history)))
1011 (if (memq 'password what) 1724 ((eq (car what) 'password) ; password
1012 (setq sql-password 1725 (setq sql-password
1013 (sql-read-passwd "Password: " sql-password))) 1726 (sql-read-passwd "Password: " sql-password)))
1014 (if (memq 'server what) 1727 ((eq (car what) 'server) ; server
1015 (setq sql-server 1728 (setq sql-server
1016 (read-from-minibuffer "Server: " sql-server nil nil 1729 (read-from-minibuffer "Server: " sql-server nil nil
1017 sql-server-history))) 1730 sql-server-history)))
1018 (if (memq 'database what) 1731 ((eq (car what) 'database) ; database
1019 (setq sql-database 1732 (setq sql-database
1020 (read-from-minibuffer "Database: " sql-database nil nil 1733 (read-from-minibuffer "Database: " sql-database nil nil
1021 sql-database-history)))) 1734 sql-database-history))))
1735 (setq what (cdr what))))
1022 1736
1023(defun sql-find-sqli-buffer () 1737(defun sql-find-sqli-buffer ()
1024 "Return the current default SQLi buffer or nil. 1738 "Return the current default SQLi buffer or nil.