comparison lisp/progmodes/sql.el @ 52242:f5ada28bb9f0

Patch by Michael Mauger <mmaug@yahoo.com> 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.el (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.
author Alex Schroeder <alex@gnu.org>
date Mon, 18 Aug 2003 17:29:23 +0000
parents 3da2cf447bf9
children 695cf19ef79e
comparison
equal deleted inserted replaced
52241:0b4e04022bd6 52242:f5ada28bb9f0
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
11 ;; This file is part of GNU Emacs. 11 ;; This file is part of GNU Emacs.
12 12
76 ;; and the custom package 76 ;; and the custom package
77 ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>. 77 ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>.
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
87 ;; Quoted identifiers are not supported for hilighting. Most
88 ;; databases support the use of double quoted strings in place of
89 ;; identifiers; ms (Microsoft SQLServer) also supports identifiers
90 ;; enclosed within brackets [].
86 91
87 ;; ChangeLog available on request. 92 ;; ChangeLog available on request.
93
94 ;;; Product Support:
95
96 ;; To add support for additional SQL products the following steps
97 ;; must be followed ("xyz" is the name of the product in the examples
98 ;; below):
99
100 ;; 1) Add the product to `sql-product' choice list.
101
102 ;; (const :tag "XyzDB" xyz)
103
104 ;; 2) Add an entry to the `sql-product-support' list.
105
106 ;; (xyz
107 ;; :font-lock sql-mode-xyz-font-lock-keywords
108 ;; :sqli-login (user password server database)
109 ;; :sqli-connect sql-connect-xyz
110 ;; :sqli-prompt-regexp "^xyzdb> "
111 ;; :sqli-prompt-length 7
112 ;; :sqli-input-sender nil
113 ;; :syntax-alist ((?# . "w")))
114
115 ;; 3) Add customizable values for the product interpreter and options.
116
117 ;; ;; Customization for XyzDB
118 ;;
119 ;; (defcustom sql-xyz-program "ixyz"
120 ;; "*Command to start ixyz by XyzDB."
121 ;; :type 'file
122 ;; :group 'SQL)
123 ;;
124 ;; (defcustom sql-xyz-options '("-X" "-Y" "-Z")
125 ;; "*List of additional options for `sql-xyz-program'."
126 ;; :type '(repeat string)
127 ;; :group 'SQL)
128
129 ;; 4) Add an entry to SQL->Product submenu.
130
131 ;; ["XyzDB" sql-highlight-xyz-keywords
132 ;; :style radio
133 ;; :selected (eq sql-product 'xyz)]
134
135 ;; 5) Add the font-lock specifications. At a minimum, default to
136 ;; using ANSI keywords. See sql-mode-oracle-font-lock-keywords for
137 ;; a more complex example.
138
139 ;; (defvar sql-mode-xyz-font-lock-keywords sql-mode-ansi-font-lock-keywords
140 ;; "XyzDB SQL keywords used by font-lock.")
141
142 ;; 6) Add a product highlighting function.
143
144 ;; (defun sql-highlight-xyz-keywords ()
145 ;; "Highlight XyzDB keywords."
146 ;; (interactive)
147 ;; (sql-set-product 'xyz))
148
149 ;; 7) Add an autoloaded SQLi function.
150
151 ;; ;;;###autoload
152 ;; (defun sql-xyz ()
153 ;; "Run ixyz by XyzDB as an inferior process."
154 ;; (interactive)
155 ;; (sql-product-interactive 'xyz))
156
157 ;; 8) Add a connect function which formats the command line arguments
158 ;; and starts the product interpreter in a comint buffer. See the
159 ;; existing connect functions for examples of the types of
160 ;; processing available.
161
162 ;; (defun sql-connect-xyz ()
163 ;; "Create comint buffer and connect to XyzDB using the login
164 ;; parameters and command options."
165 ;;
166 ;; ;; Do something with `sql-user', `sql-password',
167 ;; ;; `sql-database', and `sql-server'.
168 ;; (let ((params sql-xyz-options))
169 ;; (if (not (string= "" sql-server))
170 ;; (setq params (append (list "-S" sql-server) params)))
171 ;; (if (not (string= "" sql-database))
172 ;; (setq params (append (list "-D" sql-database) params)))
173 ;; (if (not (string= "" sql-password))
174 ;; (setq params (append (list "-P" sql-password) params)))
175 ;; (if (not (string= "" sql-user))
176 ;; (setq params (append (list "-U" sql-user) params)))
177 ;; (set-buffer (apply 'make-comint "SQL" sql-xyz-program
178 ;; nil params))))
179
180 ;; 9) Save and compile sql.el.
88 181
89 ;;; To Do: 182 ;;; To Do:
90 183
91 ;; Add better hilight support for other brands; there is a bias towards 184 ;; 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 185 ;; Oracle because that's what I use at work. Anybody else just send in
103 ;; <ibalaban@dalet.com> 196 ;; <ibalaban@dalet.com>
104 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il> 197 ;; Yair Friedman <yfriedma@JohnBryce.Co.Il>
105 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> 198 ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
106 ;; nino <nino@inform.dk> 199 ;; nino <nino@inform.dk>
107 ;; Berend de Boer <berend@pobox.com> 200 ;; Berend de Boer <berend@pobox.com>
201 ;; Michael Mauger <mmaug@yahoo.com>
108 202
109 203
110 204
111 ;;; Code: 205 ;;; Code:
112 206
113 (require 'comint) 207 (require 'comint)
114 ;; Need the following to allow GNU Emacs 19 to compile the file. 208 ;; Need the following to allow GNU Emacs 19 to compile the file.
115 (require 'regexp-opt) 209 (eval-when-compile
210 (require 'regexp-opt))
116 (require 'custom) 211 (require 'custom)
117 212
118 ;;; Allow customization 213 ;;; Allow customization
119 214
120 (defgroup SQL nil 215 (defgroup SQL nil
121 "Running a SQL interpreter from within Emacs buffers" 216 "Running a SQL interpreter from within Emacs buffers"
122 :version "20.4" 217 :version "20.4"
123 :group 'processes) 218 :group 'processes)
124 219
125 ;; These three variables will be used as defaults, if set. 220 ;; These four variables will be used as defaults, if set.
126 221
127 (defcustom sql-user "" 222 (defcustom sql-user ""
128 "*Default username." 223 "*Default username."
129 :type 'string 224 :type 'string
130 :group 'SQL) 225 :group 'SQL)
144 239
145 (defcustom sql-server "" 240 (defcustom sql-server ""
146 "*Default server or host." 241 "*Default server or host."
147 :type 'string 242 :type 'string
148 :group 'SQL) 243 :group 'SQL)
244
245 ;; SQL Product support
246 (defcustom sql-product 'ansi
247 "*Select the SQL database product used so that buffers can be
248 highlighted properly when you open them."
249 :type '(choice (const :tag "ANSI" ansi)
250 (const :tag "DB2" db2)
251 (const :tag "Informix" informix)
252 (const :tag "Ingres" ingres)
253 (const :tag "Interbase" interbase)
254 (const :tag "Linter" linter)
255 (const :tag "Microsoft" ms)
256 (const :tag "MySQL" mysql)
257 (const :tag "Oracle" oracle)
258 (const :tag "PostGres" postgres)
259 (const :tag "Solid" solid)
260 (const :tag "SQLite" sqlite)
261 (const :tag "Sybase" sybase))
262 :group 'SQL)
263
264 (defvar sql-interactive-product nil
265 "Product under `sql-interactive-mode'.")
266
267 (defvar sql-product-support
268 '((ansi
269 :font-lock sql-mode-ansi-font-lock-keywords)
270 (db2
271 :font-lock sql-mode-db2-font-lock-keywords
272 :sqli-login nil
273 :sqli-connect sql-connect-db2
274 :sqli-prompt-regexp "^db2 => "
275 :sqli-prompt-length 7)
276 (informix
277 :font-lock sql-mode-informix-font-lock-keywords
278 :sqli-login (database)
279 :sqli-connect sql-connect-informix
280 :sqli-prompt-regexp "^SQL> "
281 :sqli-prompt-length 5)
282 (ingres
283 :font-lock sql-mode-ingres-font-lock-keywords
284 :sqli-login (database)
285 :sqli-connect sql-connect-ingres
286 :sqli-prompt-regexp "^\* "
287 :sqli-prompt-length 2)
288 (interbase
289 :font-lock sql-mode-interbase-font-lock-keywords
290 :sqli-login (user password database)
291 :sqli-connect sql-connect-interbase
292 :sqli-prompt-regexp "^SQL> "
293 :sqli-prompt-length 5)
294 (linter
295 :font-lock sql-mode-linter-font-lock-keywords
296 :sqli-login (user password database server)
297 :sqli-connect sql-connect-linter
298 :sqli-prompt-regexp "^SQL>"
299 :sqli-prompt-length 4)
300 (ms
301 :font-lock sql-mode-ms-font-lock-keywords
302 :sqli-login (user password server database)
303 :sqli-connect sql-connect-ms
304 :sqli-prompt-regexp "^[0-9]*>"
305 :sqli-prompt-length 5
306 :syntax-alist ((?@ . "w")))
307 (mysql
308 :font-lock sql-mode-mysql-font-lock-keywords
309 :sqli-login (user password database server)
310 :sqli-connect sql-connect-mysql
311 :sqli-prompt-regexp "^mysql> "
312 :sqli-prompt-length 6)
313 (oracle
314 :font-lock sql-mode-oracle-font-lock-keywords
315 :sqli-login (user password database)
316 :sqli-connect sql-connect-oracle
317 :sqli-prompt-regexp "^SQL> "
318 :sqli-prompt-length 5
319 :syntax-alist ((?$ . "w") (?# . "w")))
320 (postgres
321 :font-lock sql-mode-postgres-font-lock-keywords
322 :sqli-login (database server)
323 :sqli-connect sql-connect-postgres
324 :sqli-prompt-regexp "^.*> *"
325 :sqli-prompt-length 5)
326 (solid
327 :font-lock sql-mode-solid-font-lock-keywords
328 :sqli-login (user password server)
329 :sqli-connect sql-connect-solid
330 :sqli-prompt-regexp "^"
331 :sqli-prompt-length 0)
332 (sqlite
333 :font-lock sql-mode-sqlite-font-lock-keywords
334 :sqli-login (user password server database)
335 :sqli-connect sql-connect-sqlite
336 :sqli-prompt-regexp "^sqlite> "
337 :sqli-prompt-length 8)
338 (sybase
339 :font-lock sql-mode-sybase-font-lock-keywords
340 :sqli-login (server user password database)
341 :sqli-connect sql-connect-sybase
342 :sqli-prompt-regexp "^SQL> "
343 :sqli-prompt-length 5
344 :syntax-alist ((?@ . "w")))
345 )
346 "This variable contains a list of product features for each of the
347 SQL products handled by `sql-mode'. Without an entry in this list a
348 product will not be properly highlighted and will not support
349 `sql-interactive-mode'.
350
351 Each element in the list is in the following format:
352
353 \(PRODUCT FEATURE VALUE ...)
354
355 where PRODUCT is the appropriate value of `sql-product'. The product
356 name is then followed by FEATURE-VALUE pairs. If a FEATURE is not
357 specified, its VALUE is treated as nil. FEATURE must be one of the
358 following:
359
360 :font-lock name of the variable containing the product
361 specific font lock highlighting patterns.
362
363 :sqli-login a list of login parameters (i.e., user,
364 password, database and server) needed to
365 connect to the database.
366
367 :sqli-connect the name of a function which accepts no
368 parameters that will use the values of
369 `sql-user', `sql-password',
370 `sql-database' and `sql-server' to open a
371 comint buffer and connect to the
372 database. Do product specific
373 configuration of comint in this function.
374
375 :sqli-prompt-regexp a regular expression string that matches the
376 prompt issued by the product interpreter.
377
378 :sqli-prompt-length the length of the prompt on the line.
379
380 :syntax-alist an alist of syntax table entries to enable
381 special character treatment by font-lock and
382 imenu. ")
149 383
150 ;; misc customization of sql.el behaviour 384 ;; misc customization of sql.el behaviour
151 385
152 (defcustom sql-electric-stuff nil 386 (defcustom sql-electric-stuff nil
153 "Treat some input as electric. 387 "Treat some input as electric.
175 :group 'SQL) 409 :group 'SQL)
176 410
177 ;; imenu support for sql-mode. 411 ;; imenu support for sql-mode.
178 412
179 (defvar sql-imenu-generic-expression 413 (defvar sql-imenu-generic-expression
180 '(("Tables" "^\\s-*create\\s-+table\\s-+\\(\\w+\\)" 1) 414 ;; Items are in reverse order because they are rendered in reverse.
181 ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1)) 415 '(("Rules/Defaults" "^\\s-*create\\s-+\\(rule\\|default\\)\\s-+\\(\\w+\\)" 2)
416 ("Sequences" "^\\s-*create\\s-+sequence\\s-+\\(\\w+\\)" 1)
417 ("Triggers" "^\\s-*\\(create\\s-+\\(or\\s-+replace\\s-+\\)?\\)?trigger\\s-+\\(\\w+\\)" 3)
418 ("Functions" "^\\s-*\\(create\\s-+\\(or\\s-+replace\\s-+\\)?\\)?function\\s-+\\(\\w+\\)" 3)
419 ("Procedures" "^\\s-*\\(create\\s-+\\(or\\s-+replace\\s-+\\)?\\)?proc\\(edure\\)?\\s-+\\(\\w+\\)" 4)
420 ("Packages" "^\\s-*create\\s-+\\(or\\s-+replace\\s-+\\)?package\\s-+\\(body\\s-+\\)?\\(\\w+\\)" 3)
421 ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1)
422 ("Tables/Views" "^\\s-*create\\s-+\\(\\(global\\s-+\\)?\\(temporary\\s-+\\)?table\\|view\\)\\s-+\\(\\w+\\)" 4))
182 "Define interesting points in the SQL buffer for `imenu'. 423 "Define interesting points in the SQL buffer for `imenu'.
183 424
184 This is used to set `imenu-generic-expression' when SQL mode is 425 This is used to set `imenu-generic-expression' when SQL mode is
185 entered. Subsequent changes to sql-imenu-generic-expression will not 426 entered. Subsequent changes to sql-imenu-generic-expression will not
186 affect existing SQL buffers because imenu-generic-expression is a 427 affect existing SQL buffers because imenu-generic-expression is a
272 The program can also specify a TCP connection. See `make-comint'." 513 The program can also specify a TCP connection. See `make-comint'."
273 :type 'file 514 :type 'file
274 :group 'SQL) 515 :group 'SQL)
275 516
276 (defcustom sql-sqlite-options nil 517 (defcustom sql-sqlite-options nil
277 "*List of additional options for `sql-mysql-program'. 518 "*List of additional options for `sql-sqlite-program'.
278 The following list of options is reported to make things work 519 The following list of options is reported to make things work
279 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"." 520 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
280 :type '(repeat string) 521 :type '(repeat string)
281 :version "20.8" 522 :version "20.8"
282 :group 'SQL) 523 :group 'SQL)
351 :type 'file 592 :type 'file
352 :group 'SQL) 593 :group 'SQL)
353 594
354 ;; Customization for Microsoft 595 ;; Customization for Microsoft
355 596
356 (defcustom sql-ms-program "isql" 597 (defcustom sql-ms-program "osql"
357 "*Command to start isql by Microsoft. 598 "*Command to start osql by Microsoft.
358 599
359 Starts `sql-interactive-mode' after doing some setup. 600 Starts `sql-interactive-mode' after doing some setup.
360 601
361 The program can also specify a TCP connection. See `make-comint'." 602 The program can also specify a TCP connection. See `make-comint'."
362 :type 'file 603 :type 'file
466 the local value of `sql-buffer' using \\[sql-set-sqli-buffer].") 707 the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
467 708
468 (defvar sql-prompt-regexp nil 709 (defvar sql-prompt-regexp nil
469 "Prompt used to initialize `comint-prompt-regexp'. 710 "Prompt used to initialize `comint-prompt-regexp'.
470 711
471 You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.") 712 You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.")
472 713
473 (defvar sql-prompt-length 0 714 (defvar sql-prompt-length 0
474 "Prompt used to set `left-margin' in `sql-interactive-mode'. 715 "Prompt used to set `left-margin' in `sql-interactive-mode'.
475 716
476 You can change it on `sql-interactive-mode-hook'.") 717 You can change `sql-prompt-length' on `sql-interactive-mode-hook'.")
477 718
478 (defvar sql-alternate-buffer-name nil 719 (defvar sql-alternate-buffer-name nil
479 "Buffer-local string used to possibly rename the SQLi buffer. 720 "Buffer-local string used to possibly rename the SQLi buffer.
480 721
481 Used by `sql-rename-buffer'.") 722 Used by `sql-rename-buffer'.")
516 '("SQL" 757 '("SQL"
517 ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer) 758 ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer)
518 (get-buffer-process sql-buffer))] 759 (get-buffer-process sql-buffer))]
519 ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs 760 ["Send Region" sql-send-region (and (or (and (boundp 'mark-active); Emacs
520 mark-active) 761 mark-active)
521 (mark)); XEmacs 762 (mark t)); XEmacs
522 (buffer-live-p sql-buffer) 763 (buffer-live-p sql-buffer)
523 (get-buffer-process sql-buffer))] 764 (get-buffer-process sql-buffer))]
524 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) 765 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)
525 (get-buffer-process sql-buffer))] 766 (get-buffer-process sql-buffer))]
767 ["--" nil nil]
768 ["Start SQLi session" sql-product-interactive (sql-product-feature :sqli-connect)]
526 ["Show SQLi buffer" sql-show-sqli-buffer t] 769 ["Show SQLi buffer" sql-show-sqli-buffer t]
527 ["Set SQLi buffer" sql-set-sqli-buffer t] 770 ["Set SQLi buffer" sql-set-sqli-buffer t]
528 ["Pop to SQLi buffer after send" 771 ["Pop to SQLi buffer after send"
529 sql-toggle-pop-to-buffer-after-send-region 772 sql-toggle-pop-to-buffer-after-send-region
530 :style toggle 773 :style toggle
531 :selected sql-pop-to-buffer-after-send-region] 774 :selected sql-pop-to-buffer-after-send-region]
532 ("Highlighting" 775 ["--" nil nil]
533 ["ANSI SQL keywords" sql-highlight-ansi-keywords t] 776 ("Product"
534 ["Oracle keywords" sql-highlight-oracle-keywords t] 777 ["ANSI" sql-highlight-ansi-keywords
535 ["Postgres keywords" sql-highlight-postgres-keywords t] 778 :style radio
536 ["Linter keywords" sql-highlight-linter-keywords t] 779 :selected (eq sql-product 'ansi)]
780 ["DB2" sql-highlight-db2-keywords
781 :style radio
782 :selected (eq sql-product 'db2)]
783 ["Informix" sql-highlight-informix-keywords
784 :style radio
785 :selected (eq sql-product 'informix)]
786 ["Ingres" sql-highlight-ingres-keywords
787 :style radio
788 :selected (eq sql-product 'ingres)]
789 ["Interbase" sql-highlight-interbase-keywords
790 :style radio
791 :selected (eq sql-product 'interbase)]
792 ["Linter" sql-highlight-linter-keywords
793 :style radio
794 :selected (eq sql-product 'linter)]
795 ["Microsoft" sql-highlight-ms-keywords
796 :style radio
797 :selected (eq sql-product 'ms)]
798 ["MySQL" sql-highlight-mysql-keywords
799 :style radio
800 :selected (eq sql-product 'mysql)]
801 ["Oracle" sql-highlight-oracle-keywords
802 :style radio
803 :selected (eq sql-product 'oracle)]
804 ["Postgres" sql-highlight-postgres-keywords
805 :style radio
806 :selected (eq sql-product 'postgres)]
807 ["Solid" sql-highlight-solid-keywords
808 :style radio
809 :selected (eq sql-product 'solid)]
810 ["SQLite" sql-highlight-sqlite-keywords
811 :style radio
812 :selected (eq sql-product 'sqlite)]
813 ["Sybase" sql-highlight-sybase-keywords
814 :style radio
815 :selected (eq sql-product 'sybase)]
537 ))) 816 )))
538 817
539 ;; easy menu for sql-interactive-mode. 818 ;; easy menu for sql-interactive-mode.
540 819
541 (easy-menu-define 820 (easy-menu-define
549 828
550 (defvar sql-mode-abbrev-table nil 829 (defvar sql-mode-abbrev-table nil
551 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.") 830 "Abbrev table used in `sql-mode' and `sql-interactive-mode'.")
552 (if sql-mode-abbrev-table 831 (if sql-mode-abbrev-table
553 () 832 ()
554 (let ((wrapper)) 833 (let ((nargs (cdr (subr-arity (symbol-function 'define-abbrev))))
555 (define-abbrev-table 'sql-mode-abbrev-table ()) 834 d-a)
556 (define-abbrev sql-mode-abbrev-table "ins" "insert") 835 ;; In Emacs 21.3+, provide SYSTEM-FLAG to define-abbrev.
557 (define-abbrev sql-mode-abbrev-table "upd" "update") 836 (setq d-a
558 (define-abbrev sql-mode-abbrev-table "del" "delete") 837 (if (>= nargs 6)
559 (define-abbrev sql-mode-abbrev-table "sel" "select"))) 838 '(lambda (name expansion) (define-abbrev sql-mode-abbrev-table name expansion nil 0 t))
839 '(lambda (name expansion) (define-abbrev sql-mode-abbrev-table name expansion))))
840
841 (define-abbrev-table 'sql-mode-abbrev-table nil)
842 (funcall d-a "ins" "insert")
843 (funcall d-a "upd" "update")
844 (funcall d-a "del" "delete")
845 (funcall d-a "sel" "select")
846 (funcall d-a "proc" "procedure")
847 (funcall d-a "func" "function")
848 (funcall d-a "cr" "create")))
560 849
561 ;; Syntax Table 850 ;; Syntax Table
562 851
563 (defvar sql-mode-syntax-table 852 (defvar sql-mode-syntax-table
564 (let ((table (make-syntax-table))) 853 (let ((table (make-syntax-table)))
579 table) 868 table)
580 "Syntax table used in `sql-mode' and `sql-interactive-mode'.") 869 "Syntax table used in `sql-mode' and `sql-interactive-mode'.")
581 870
582 ;; Font lock support 871 ;; Font lock support
583 872
584 (defvar sql-mode-ansi-font-lock-keywords nil 873 (defvar sql-mode-font-lock-object-name
874 (list (concat "^\\s-*\\(create\\(\\s-+or\\s-+replace\\)?\\|drop\\|alter\\)?\\s-+"
875 "\\(\\(global\\s-+\\)?\\(temporary\\s-+\\)?table\\|view\\|package\\(\\s-+body\\)?\\|"
876 "proc\\(edure\\)?\\|function\\|trigger\\|sequence\\|rule\\|default\\)\\s-+\\(\\w+\\)")
877 8 'font-lock-function-name-face)
878
879 "Pattern to match the names of top-level objects in a CREATE,
880 DROP or ALTER statement.
881
882 The format of variable should be a valid `font-lock-keywords'
883 entry.")
884
885 (defvar sql-mode-ansi-font-lock-keywords
886 (let ((ansi-keywords (eval-when-compile
887 (concat "\\b"
888 (regexp-opt '(
889
890 "authorization" "avg" "begin" "close" "cobol" "commit"
891 "continue" "count" "declare" "double" "end" "escape"
892 "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"
893 "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli"
894 "precision" "primary" "procedure" "references" "rollback"
895 "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work"
896
897 ) t) "\\b")))
898 (ansi-reserved-words (eval-when-compile
899 (concat "\\b"
900 (regexp-opt '(
901
902 "all" "and" "any" "as" "asc" "between" "by" "check" "create"
903 "current" "default" "delete" "desc" "distinct" "exists" "float" "for"
904 "from" "grant" "group" "having" "in" "insert" "into" "is"
905 "like" "not" "null" "of" "on" "option" "or" "order" "privileges"
906 "public" "select" "set" "table" "to" "union" "unique"
907 "update" "user" "values" "view" "where" "with"
908
909 ) t) "\\b")))
910 (ansi-types (eval-when-compile
911 (concat "\\b"
912 (regexp-opt '(
913
914 ;; ANSI Keywords that look like types
915 "character" "cursor" "dec" "int" "real"
916 ;; ANSI Reserved Word that look like types
917 "char" "integer" "smallint"
918
919 ) t) "\\b"))))
920 (list (cons ansi-keywords 'font-lock-keyword-face)
921 (cons ansi-reserved-words 'font-lock-keyword-face)
922 (cons ansi-types 'font-lock-type-face)))
923
585 "ANSI SQL keywords used by font-lock. 924 "ANSI SQL keywords used by font-lock.
586 925
587 This variable is used by `sql-mode' and `sql-interactive-mode'. The 926 This variable is used by `sql-mode' and `sql-interactive-mode'. The
588 regular expressions are created during compilation by calling the 927 regular expressions are created during compilation by calling the
589 function `regexp-opt'. Therefore, take a look at the source before 928 function `regexp-opt'. Therefore, take a look at the source before
590 you define your own sql-mode-ansi-font-lock-keywords. You may want to 929 you define your own sql-mode-ansi-font-lock-keywords. You may want to
591 add functions and PL/SQL keywords.") 930 add functions and PL/SQL keywords.")
592 (if sql-mode-ansi-font-lock-keywords 931
593 () 932 (defvar sql-mode-oracle-font-lock-keywords
594 (let ((ansi-keywords (eval-when-compile 933 (let ((oracle-keywords (eval-when-compile
595 (concat "\\b" 934 (concat "\\b"
596 (regexp-opt '( 935 (regexp-opt '(
936 ;; Oracle (+ANSI) SQL keywords
937
938 ; ANSI keywords
597 "authorization" "avg" "begin" "close" "cobol" "commit" 939 "authorization" "avg" "begin" "close" "cobol" "commit"
598 "continue" "count" "declare" "double" "end" "escape" 940 "continue" "count" "declare" "double" "end" "escape"
599 "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator" 941 "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"
600 "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli" 942 "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli"
601 "precision" "primary" "procedure" "references" "rollback" 943 "precision" "primary" "procedure" "references" "rollback"
602 "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work") t) "\\b"))) 944 "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work"
603 (ansi-reserved-words (eval-when-compile 945
604 (concat "\\b" 946 ; ANSI reserved words
605 (regexp-opt '(
606 "all" "and" "any" "as" "asc" "between" "by" "check" "create" 947 "all" "and" "any" "as" "asc" "between" "by" "check" "create"
607 "current" "default" "delete" "desc" "distinct" "exists" "float" "for" 948 "current" "default" "delete" "desc" "distinct" "exists" "float" "for"
608 "from" "grant" "group" "having" "in" "insert" "into" "is" 949 "from" "grant" "group" "having" "in" "insert" "into" "is"
609 "like" "not" "null" "of" "on" "option" "or" "order" "privileges" 950 "like" "not" "null" "of" "on" "option" "or" "order" "privileges"
610 "public" "select" "set" "table" "to" "union" "unique" 951 "public" "select" "set" "table" "to" "union" "unique"
611 "update" "user" "values" "view" "where" "with") t) "\\b"))) 952 "update" "user" "values" "view" "where" "with"
612 (ansi-types (eval-when-compile 953
613 (concat "\\b" 954 "access" "add" "admin" "after" "allocate" "alter" "analyze" "archive"
614 (regexp-opt '( 955 "archivelog" "audit" "authid" "backup" "become" "before" "block"
615 ;; ANSI Keywords that look like types 956 "body" "cache" "cancel" "cascade" "change" "checkpoint" "cluster"
616 "character" "cursor" "dec" "int" "real" 957 "comment" "compile" "compress" "compute" "connect" "constraint"
617 ;; ANSI Reserved Word that look like types 958 "constraints" "contents" "controlfile" "cross" "currval" "cycle"
618 "char" "integer" "smallint" ) t) "\\b")))) 959 "database" "datafile" "dba" "deterministic" "disable" "dismount"
619 (setq sql-mode-ansi-font-lock-keywords 960 "drop" "dump" "each" "else" "else" "elsif" "enable" "events" "except"
620 (list (cons ansi-keywords 'font-lock-function-name-face) 961 "exceptions" "exclusive" "execute" "exit" "explain" "extent"
621 (cons ansi-reserved-words 'font-lock-keyword-face) 962 "externally" "false" "file" "flush" "force" "freelist" "freelists"
622 (cons ansi-types 'font-lock-type-face))))) 963 "full" "function" "global" "grant" "groups" "identified" "if"
623 964 "immediate" "including" "increment" "index" "initial" "initrans"
624 (defvar sql-mode-oracle-font-lock-keywords nil 965 "inner" "instance" "intersect" "join" "layer" "left" "level" "link"
966 "lists" "lock" "logfile" "long" "loop" "manage" "manual"
967 "maxdatafiles" "maxextents" "maxinistances" "maxlogfiles"
968 "maxloghistory" "maxlogmembers" "maxtrans" "maxvalue" "merge"
969 "minextents" "minus" "minvalue" "mode" "modify" "mount" "natural"
970 "new" "next" "nextval" "noarchivelog" "noaudit" "nocache" "nocompress"
971 "nocycle" "nomaxvalue" "nominvalue" "none" "noorder" "noresetlogs"
972 "normal" "nosort" "nowait" "off" "offline" "old" "online" "only"
973 "optimal" "others" "out" "outer" "over" "own" "package" "parallel"
974 "parallel_enable" "pctfree" "pctincrease" "pctused" "plan" "pragma"
975 "preserve" "prior" "private" "profile" "quota" "raise" "raw" "read"
976 "recover" "referencing" "rename" "replace" "resetlogs" "resource"
977 "restrict_references" "restricted" "return" "returning" "reuse"
978 "revoke" "right" "rnds" "rnps" "role" "roles" "row" "rowlabel"
979 "rownum" "rows" "savepoint" "scn" "segment" "sequence" "session"
980 "share" "shared" "size" "snapshot" "sort" "statement_id" "statistics"
981 "stop" "storage" "subtype" "successful" "switch" "synonym" "sysdate"
982 "system" "tables" "tablespace" "temporary" "then" "thread" "tracing"
983 "transaction" "trigger" "triggers" "true" "truncate" "type" "uid"
984 "under" "unlimited" "until" "use" "using" "validate" "when" "while"
985 "wnds" "wnps" "write"
986
987 ) t) "\\b")))
988 (oracle-warning-words (eval-when-compile
989 (concat "\\b"
990 (regexp-opt '(
991 ;; PLSQL defined exceptions
992
993 "access_into_null" "case_not_found" "collection_is_null"
994 "cursor_already_open" "dup_val_on_index" "invalid_cursor"
995 "invalid_number" "login_denied" "no_data_found" "not_logged_on"
996 "program_error" "rowtype_mismatch" "self_is_null" "storage_error"
997 "subscript_beyond_count" "subscript_outside_limit" "sys_invalid_rowid"
998 "timeout_on_resource" "too_many_rows" "value_error" "zero_divide"
999 "exception" "notfound"
1000
1001 ) t) "\\b")))
1002
1003 (oracle-sqlplus-commands
1004 (eval-when-compile
1005 (concat "^\\(\\("
1006 (regexp-opt '(
1007 ;; SQL*Plus commands
1008
1009 "@" "@@" "accept" "append" "archive" "attribute" "break"
1010 "btitle" "change" "clear" "column" "connect" "copy" "define"
1011 "del" "describe" "disconnect" "edit" "execute" "exit" "get" "help"
1012 "host" "input" "list" "password" "pause" "print" "prompt" "recover"
1013 "remark" "repfooter" "repheader" "run" "save" "show" "shutdown"
1014 "spool" "start" "startup" "store" "timing" "ttitle" "undefine"
1015 "variable" "whenever"
1016
1017 ) t)
1018
1019 "\\)\\|"
1020 "\\(compute\\s-+\\(avg\\|cou\\|min\\|max\\|num\\|sum\\|std\\|var\\)\\)\\|"
1021 "\\(set\\s-+\\(appi\\(nfo\\)?\\|array\\(size\\)?\\|"
1022 "auto\\(commit\\)?\\|autop\\(rint\\)?\\|autorecovery\\|"
1023 "autot\\(race\\)?\\|blo\\(ckterminator\\)?\\|cmds\\(ep\\)?\\|"
1024 "colsep\\|com\\(patibility\\)?\\|con\\(cat\\)?\\|"
1025 "copyc\\(ommit\\)?\\|copytypecheck\\|def\\(ine\\)?\\|"
1026 "describe\\|echo\\|editf\\(ile\\)?\\|emb\\(edded\\)?\\|"
1027 "esc\\(ape\\)?\\|feed\\(back\\)?\\|flagger\\|"
1028 "flu\\(sh\\)?\\|hea\\(ding\\)?\\|heads\\(ep\\)?\\|"
1029 "instance\\|lin\\(esize\\)?\\|lobof\\(fset\\)?\\|"
1030 "logsource\\|long\\|longc\\(hunksize\\)?\\|mark\\(up\\)?\\|"
1031 "newp\\(age\\)?\\|null\\|numf\\(ormat\\)?\\|"
1032 "num\\(width\\)?\\|pages\\(ize\\)?\\|pau\\(se\\)?\\|"
1033 "recsep\\|recsepchar\\|serverout\\(put\\)?\\|"
1034 "shift\\(inout\\)?\\|show\\(mode\\)?\\|"
1035 "sqlbl\\(anklines\\)?\\|sqlc\\(ase\\)?\\|"
1036 "sqlco\\(ntinue\\)?\\|sqln\\(umber\\)?\\|"
1037 "sqlpluscompat\\(ibility\\)?\\|sqlpre\\(fix\\)?\\|"
1038 "sqlp\\(rompt\\)?\\|sqlt\\(erminator\\)?\\|"
1039 "suf\\(fix\\)?\\|tab\\|term\\(out\\)?\\|ti\\(me\\)?\\|"
1040 "timi\\(ng\\)?\\|trim\\(out\\)?\\|trims\\(pool\\)?\\|"
1041 "und\\(erline\\)?\\|ver\\(ify\\)?\\|wra\\(p\\)?\\)\\)\\)"
1042 "\\b.*$"
1043 )))
1044
1045 (oracle-types
1046 (eval-when-compile
1047 (concat "\\b"
1048 (regexp-opt '(
1049 ;; Oracle Keywords that look like types
1050 ;; Oracle Reserved Words that look like types
1051
1052 "bfile" "binary_integer" "blob" "boolean" "byte" "char" "character"
1053 "clob" "date" "day" "dec" "decimal" "double" "float" "int" "integer"
1054 "interval" "local" "long" "month" "natural" "naturaln" "nchar" "nclob"
1055 "number" "numeric" "nvarchar2" "pls_integer" "positive" "positiven"
1056 "precision" "raw" "real" "rowid" "second" "signtype" "smallint"
1057 "string" "time" "timestamp" "urowid" "varchar" "varchar2" "year"
1058 "zone"
1059
1060 ) t) "\\b")))
1061 (oracle-builtin-functions (eval-when-compile
1062 (concat "\\b"
1063 (regexp-opt '(
1064 ;; Misc Oracle builtin functions
1065
1066 "abs" "acos" "add_months" "ascii" "asciistr" "asin" "atan" "atan2"
1067 "avg" "bfilename" "bin_to_num" "bitand" "case" "cast" "ceil"
1068 "chartorowid" "chr" "coalesce" "compose" "concat" "convert" "corr"
1069 "cos" "cosh" "count" "covar_pop" "covar_samp" "cume_dist"
1070 "current_date" "current_timestamp" "current_user" "dbtimezone"
1071 "decode" "decompose" "dense_rank" "depth" "deref" "dump" "empty_blob"
1072 "empty_clob" "existsnode" "exp" "extract" "extractvalue" "first"
1073 "first_value" "floor" "from_tz" "greatest" "group_id" "grouping"
1074 "grouping_id" "hextoraw" "initcap" "instr" "lag" "last" "last_day"
1075 "last_value" "lead" "least" "length" "ln" "localtimestamp" "log"
1076 "lower" "lpad" "ltrim" "make_ref" "max" "min" "mod" "months_between"
1077 "nchr" "new_time" "next_day" "nls_charset_decl_len" "nls_charset_id"
1078 "nls_charset_name" "nls_initcap" "nls_lower" "nlssort" "nls_upper"
1079 "ntile" "nullif" "numtodsinterval" "numtoyminterval" "nvl" "nvl2"
1080 "path" "percent_rank" "percentile_cont" "percentile_disc" "power"
1081 "rank" "ratio_to_report" "rawtohex" "rawtonhex" "ref" "reftohex"
1082 "regr_slope" "regr_intercept" "regr_count" "regr_r2" "regr_avgx"
1083 "regr_avgy" "regr_sxx" "regr_syy" "regr_sxy" "round"
1084 "row_number" "rowidtochar" "rowidtonchar" "rpad" "rtrim"
1085 "sessiontimezone" "sign" "sin" "sinh" "soundex" "sqrt" "stddev"
1086 "stddev_pop" "stddev_samp" "substr" "sum" "sys_connect_by_path"
1087 "sys_context" "sys_dburigen" "sys_extract_utc" "sys_guid" "sys_typeid"
1088 "sys_xmlagg" "sys_xmlgen" "sysdate" "systimestamp" "tan" "tanh"
1089 "to_char" "to_clob" "to_date" "to_dsinterval" "to_lob" "to_multi_byte"
1090 "to_nchar" "to_nclob" "to_number" "to_single_byte" "to_timestamp"
1091 "to_timestamp_tz" "to_yminterval" "translate" "treat" "trim" "trunc"
1092 "tz_offset" "uid" "unistr" "updatexml" "upper" "user" "userenv"
1093 "value" "var_pop" "var_samp" "variance" "vsize" "width_bucket"
1094 "xmlagg" "xmlcolattval" "xmlconcat" "xmlelement" "xmlforest"
1095 "xmlsequence" "xmltransform"
1096
1097 ) t) "\\b"))))
1098 (list (cons oracle-sqlplus-commands 'font-lock-doc-face)
1099 (cons oracle-keywords 'font-lock-keyword-face)
1100 (cons oracle-warning-words 'font-lock-warning-face)
1101 ;; XEmacs doesn't have font-lock-builtin-face
1102 (if (string-match "XEmacs\\|Lucid" emacs-version)
1103 (cons oracle-builtin-functions 'font-lock-preprocessor-face)
1104 ;; GNU Emacs 19 doesn't have it either
1105 (if (string-match "GNU Emacs 19" emacs-version)
1106 (cons oracle-builtin-functions 'font-lock-keyword-face)
1107 ;; Emacs
1108 (cons oracle-builtin-functions 'font-lock-builtin-face)))
1109 (cons oracle-types 'font-lock-type-face)))
1110
625 "Oracle SQL keywords used by font-lock. 1111 "Oracle SQL keywords used by font-lock.
626 1112
627 This variable is used by `sql-mode' and `sql-interactive-mode'. The 1113 This variable is used by `sql-mode' and `sql-interactive-mode'. The
628 regular expressions are created during compilation by calling the 1114 regular expressions are created during compilation by calling the
629 function `regexp-opt'. Therefore, take a look at the source before 1115 function `regexp-opt'. Therefore, take a look at the source before
630 you define your own sql-mode-oracle-font-lock-keywords. You may want 1116 you define your own sql-mode-oracle-font-lock-keywords. You may want
631 to add functions and PL/SQL keywords.") 1117 to add functions and PL/SQL keywords.")
632 (if sql-mode-oracle-font-lock-keywords 1118
633 () 1119 (defvar sql-mode-postgres-font-lock-keywords
634 (let ((oracle-keywords (eval-when-compile
635 (concat "\\b"
636 (regexp-opt '(
637 "admin" "after" "allocate" "analyze" "archive" "archivelog" "backup"
638 "become" "before" "block" "body" "cache" "cancel" "cascade" "change"
639 "checkpoint" "compile" "constraint" "constraints" "contents"
640 "controlfile" "cycle" "database" "datafile" "dba" "disable" "dismount"
641 "dump" "each" "else" "elsif" "enable" "events" "except" "exceptions"
642 "execute" "exit" "explain" "extent" "externally" "false" "flush" "force"
643 "freelist" "freelists" "function" "groups" "if" "including" "initrans"
644 "instance" "layer" "link" "lists" "logfile" "loop" "manage" "manual"
645 "maxdatafiles" "maxinistances" "maxlogfiles" "maxloghistory"
646 "maxlogmembers" "maxtrans" "maxvalue" "minextents" "minvalue" "mount"
647 "new" "next" "noarchivelog" "nocache" "nocycle" "nomaxvalue"
648 "nominvalue" "none" "noorder" "noresetlogs" "normal" "nosort" "off"
649 "old" "only" "optimal" "others" "out" "own" "package" "parallel"
650 "pctincrease" "pctused" "plan" "pragma" "private" "profile" "quota"
651 "raise" "read" "recover" "referencing" "resetlogs" "restrict_references"
652 "restricted" "return" "returning" "reuse" "rnds" "rnps" "role" "roles"
653 "savepoint" "scn" "segment" "sequence" "shared" "snapshot" "sort"
654 "statement_id" "statistics" "stop" "storage" "subtype" "switch" "system"
655 "tables" "tablespace" "temporary" "thread" "time" "tracing"
656 "transaction" "triggers" "true" "truncate" "type" "under" "unlimited"
657 "until" "use" "using" "when" "while" "wnds" "wnps" "write") t) "\\b")))
658 (oracle-warning-words (eval-when-compile
659 (concat "\\b"
660 (regexp-opt '(
661 "cursor_already_open" "dup_val_on_index" "exception" "invalid_cursor"
662 "invalid_number" "login_denied" "no_data_found" "not_logged_on"
663 "notfound" "others" "pragma" "program_error" "storage_error"
664 "timeout_on_resource" "too_many_rows" "transaction_backed_out"
665 "value_error" "zero_divide") t) "\\b")))
666 (oracle-reserved-words (eval-when-compile
667 (concat "\\b"
668 (regexp-opt '(
669 "access" "add" "alter" "audit" "cluster" "column" "comment" "compress"
670 "connect" "drop" "else" "exclusive" "file" "grant"
671 "identified" "immediate" "increment" "index" "initial" "intersect"
672 "level" "lock" "long" "maxextents" "minus" "mode" "modify" "noaudit"
673 "nocompress" "nowait" "number" "offline" "online" "pctfree" "prior"
674 "raw" "rename" "resource" "revoke" "row" "rowlabel" "rownum"
675 "rows" "session" "share" "size" "start" "successful" "synonym" "sysdate"
676 "then" "trigger" "uid" "validate" "whenever") t) "\\b")))
677 (oracle-types (eval-when-compile
678 (concat "\\b"
679 (regexp-opt '(
680 ;; Oracle Keywords that look like types
681 ;; Oracle Reserved Words that look like types
682 "binary_integer" "blob" "boolean" "constant" "date" "decimal" "rowid"
683 "varchar" "varchar2") t) "\\b")))
684 (oracle-builtin-functions (eval-when-compile
685 (concat "\\b"
686 (regexp-opt '(
687 ;; Misc Oracle builtin functions
688 "abs" "add_months" "ascii" "avg" "ceil" "chartorowid" "chr" "concat"
689 "convert" "cos" "cosh" "count" "currval" "decode" "dump" "exp" "floor"
690 "glb" "greatest" "greatest_lb" "hextoraw" "initcap" "instr" "instrb"
691 "last_day" "least" "least_ub" "length" "lengthb" "ln" "log" "lower"
692 "lpad" "ltrim" "lub" "max" "min" "mod" "months_between" "new_time"
693 "next_day" "nextval" "nls_initcap" "nls_lower" "nls_upper" "nlssort"
694 "nvl" "power" "rawtohex" "replace" "round" "rowidtochar" "rpad"
695 "rtrim" "sign" "sin" "sinh" "soundex" "sqlcode" "sqlerrm" "sqrt"
696 "stddev" "sum" "substr" "substrb" "tan" "tanh" "to_char"
697 "to_date" "to_label" "to_multi_byte" "to_number" "to_single_byte"
698 "translate" "trim" "trunc" "uid" "upper" "userenv" "variance" "vsize") t) "\\b"))))
699 (setq sql-mode-oracle-font-lock-keywords
700 (append sql-mode-ansi-font-lock-keywords
701 (list (cons oracle-keywords 'font-lock-function-name-face)
702 (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
705 (if (string-match "XEmacs\\|Lucid" emacs-version)
706 (cons oracle-builtin-functions 'font-lock-preprocessor-face)
707 ;; GNU Emacs 19 doesn't have it either
708 (if (string-match "GNU Emacs 19" emacs-version)
709 (cons oracle-builtin-functions 'font-lock-function-name-face)
710 ;; Emacs
711 (cons oracle-builtin-functions 'font-lock-builtin-face)))
712 (cons oracle-types 'font-lock-type-face))))))
713
714 (defvar sql-mode-postgres-font-lock-keywords nil
715 "Postgres SQL keywords used by font-lock.
716
717 This variable is used by `sql-mode' and `sql-interactive-mode'. The
718 regular expressions are created during compilation by calling the
719 function `regexp-opt'. Therefore, take a look at the source before
720 you define your own sql-mode-postgres-font-lock-keywords.")
721
722 (if sql-mode-postgres-font-lock-keywords
723 ()
724 (let ((postgres-reserved-words (eval-when-compile 1120 (let ((postgres-reserved-words (eval-when-compile
725 (concat "\\b" 1121 (concat "\\b"
726 (regexp-opt '( 1122 (regexp-opt '(
727 "language" 1123 "language"
728 ) t) "\\b"))) 1124 ) t) "\\b")))
729 (postgres-types (eval-when-compile 1125 (postgres-types (eval-when-compile
730 (concat "\\b" 1126 (concat "\\b"
731 (regexp-opt '( 1127 (regexp-opt '(
1128
732 "bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date" 1129 "bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date"
733 "float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path" 1130 "float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path"
734 "point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar" 1131 "point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar"
1132
735 ) t)"\\b"))) 1133 ) t)"\\b")))
736 (postgres-builtin-functions (eval-when-compile 1134 (postgres-builtin-functions (eval-when-compile
737 (concat "\\b" 1135 (concat "\\b"
738 (regexp-opt '( 1136 (regexp-opt '(
739 ;; Misc Postgres builtin functions 1137 ;; Misc Postgres builtin functions
1138
740 "abstime" "age" "area" "box" "center" "date_part" "date_trunc" 1139 "abstime" "age" "area" "box" "center" "date_part" "date_trunc"
741 "datetime" "dexp" "diameter" "dpow" "float" "float4" "height" 1140 "datetime" "dexp" "diameter" "dpow" "float" "float4" "height"
742 "initcap" "integer" "isclosed" "isfinite" "isoldpath" "isopen" 1141 "initcap" "integer" "isclosed" "isfinite" "isoldpath" "isopen"
743 "length" "lower" "lpad" "ltrim" "pclose" "point" "points" "popen" 1142 "length" "lower" "lpad" "ltrim" "pclose" "point" "points" "popen"
744 "position" "radius" "reltime" "revertpoly" "rpad" "rtrim" "substr" 1143 "position" "radius" "reltime" "revertpoly" "rpad" "rtrim" "substr"
745 "substring" "text" "timespan" "translate" "trim" "upgradepath" 1144 "substring" "text" "timespan" "translate" "trim" "upgradepath"
746 "upgradepoly" "upper" "varchar" "width" 1145 "upgradepoly" "upper" "varchar" "width"
1146
747 ) t) "\\b")))) 1147 ) t) "\\b"))))
748 (setq sql-mode-postgres-font-lock-keywords
749 (append sql-mode-ansi-font-lock-keywords 1148 (append sql-mode-ansi-font-lock-keywords
750 (list (cons postgres-reserved-words 'font-lock-keyword-face) 1149 (list (cons postgres-reserved-words 'font-lock-keyword-face)
751 ;; XEmacs doesn't have 'font-lock-builtin-face 1150 ;; XEmacs doesn't have 'font-lock-builtin-face
752 (if (string-match "XEmacs\\|Lucid" emacs-version) 1151 (if (string-match "XEmacs\\|Lucid" emacs-version)
753 (cons postgres-builtin-functions 'font-lock-preprocessor-face) 1152 (cons postgres-builtin-functions 'font-lock-preprocessor-face)
754 ;; Emacs 1153 ;; Emacs
755 (cons postgres-builtin-functions 'font-lock-builtin-face)) 1154 (cons postgres-builtin-functions 'font-lock-builtin-face))
756 (cons postgres-types 'font-lock-type-face)))))) 1155 (cons postgres-types 'font-lock-type-face))))
757 1156
758 1157 "Postgres SQL keywords used by font-lock.
759 (defvar sql-mode-linter-font-lock-keywords nil
760 "Linter SQL keywords used by font-lock.
761 1158
762 This variable is used by `sql-mode' and `sql-interactive-mode'. The 1159 This variable is used by `sql-mode' and `sql-interactive-mode'. The
763 regular expressions are created during compilation by calling the 1160 regular expressions are created during compilation by calling the
764 function `regexp-opt'.") 1161 function `regexp-opt'. Therefore, take a look at the source before
765 1162 you define your own sql-mode-postgres-font-lock-keywords.")
766 (if sql-mode-linter-font-lock-keywords 1163
767 () 1164 (defvar sql-mode-linter-font-lock-keywords
768 (let ((linter-keywords (eval-when-compile 1165 (let ((linter-keywords (eval-when-compile
769 (concat "\\b" 1166 (concat "\\b"
770 (regexp-opt '( 1167 (regexp-opt '(
1168
771 "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel" 1169 "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel"
772 "committed" "count" "countblob" "cross" "current" "data" "database" 1170 "committed" "count" "countblob" "cross" "current" "data" "database"
773 "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred" 1171 "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred"
774 "denied" "description" "device" "difference" "directory" "error" 1172 "denied" "description" "device" "difference" "directory" "error"
775 "escape" "euc" "exclusive" "external" "extfile" "false" "file" 1173 "escape" "euc" "exclusive" "external" "extfile" "false" "file"
790 "startup" "statement" "station" "success" "sys_guid" "tables" "test" 1188 "startup" "statement" "station" "success" "sys_guid" "tables" "test"
791 "timeout" "trace" "transaction" "translation" "trigger" 1189 "timeout" "trace" "transaction" "translation" "trigger"
792 "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown" 1190 "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown"
793 "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes" 1191 "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes"
794 "wait" "windows_code" "workspace" "write" "xml" 1192 "wait" "windows_code" "workspace" "write" "xml"
1193
795 ) t) "\\b"))) 1194 ) t) "\\b")))
796 (linter-reserved-words (eval-when-compile 1195 (linter-reserved-words (eval-when-compile
797 (concat "\\b" 1196 (concat "\\b"
798 (regexp-opt '( 1197 (regexp-opt '(
1198
799 "access" "action" "add" "address" "after" "all" "alter" "always" "and" 1199 "access" "action" "add" "address" "after" "all" "alter" "always" "and"
800 "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit" 1200 "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit"
801 "aud_obj_name_len" "backup" "base" "before" "between" "blobfile" 1201 "aud_obj_name_len" "backup" "base" "before" "between" "blobfile"
802 "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check" 1202 "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check"
803 "clear" "close" "column" "comment" "commit" "connect" "contains" 1203 "clear" "close" "column" "comment" "commit" "connect" "contains"
811 "purge" "rebuild" "resource" "restrict" "revoke" "right" "role" 1211 "purge" "rebuild" "resource" "restrict" "revoke" "right" "role"
812 "rollback" "rownum" "select" "session" "set" "share" "shutdown" 1212 "rollback" "rownum" "select" "session" "set" "share" "shutdown"
813 "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then" 1213 "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then"
814 "to" "union" "unique" "unlock" "until" "update" "using" "values" 1214 "to" "union" "unique" "unlock" "until" "update" "using" "values"
815 "view" "when" "where" "with" "without" 1215 "view" "when" "where" "with" "without"
1216
816 ) t) "\\b"))) 1217 ) t) "\\b")))
817 (linter-types (eval-when-compile 1218 (linter-types (eval-when-compile
818 (concat "\\b" 1219 (concat "\\b"
819 (regexp-opt '( 1220 (regexp-opt '(
1221
820 "bigint" "bitmap" "blob" "boolean" "char" "character" "date" 1222 "bigint" "bitmap" "blob" "boolean" "char" "character" "date"
821 "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar" 1223 "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar"
822 "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte" 1224 "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte"
823 "cursor" "long" 1225 "cursor" "long"
1226
824 ) t) "\\b"))) 1227 ) t) "\\b")))
825 (linter-builtin-functions (eval-when-compile 1228 (linter-builtin-functions (eval-when-compile
826 (concat "\\b" 1229 (concat "\\b"
827 (regexp-opt '( 1230 (regexp-opt '(
1231
828 "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime" 1232 "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime"
829 "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw" 1233 "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw"
830 "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log" 1234 "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log"
831 "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl" 1235 "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl"
832 "octet_length" "power" "rand" "rawtohex" "repeat_string" 1236 "octet_length" "power" "rand" "rawtohex" "repeat_string"
833 "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex" 1237 "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex"
834 "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date" 1238 "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date"
835 "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode" 1239 "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode"
836 "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap" 1240 "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap"
837 "instr" "least" "multime" "replace" "width" 1241 "instr" "least" "multime" "replace" "width"
1242
838 ) t) "\\b")))) 1243 ) t) "\\b"))))
839 (setq sql-mode-linter-font-lock-keywords
840 (append sql-mode-ansi-font-lock-keywords 1244 (append sql-mode-ansi-font-lock-keywords
841 (list (cons linter-keywords 'font-lock-function-name-face) 1245 (list (cons linter-keywords 'font-lock-keywords-face)
842 (cons linter-reserved-words 'font-lock-keyword-face) 1246 (cons linter-reserved-words 'font-lock-keyword-face)
843 ;; XEmacs doesn't have font-lock-builtin-face 1247 ;; XEmacs doesn't have font-lock-builtin-face
844 (if (string-match "XEmacs\\|Lucid" emacs-version) 1248 (if (string-match "XEmacs\\|Lucid" emacs-version)
845 (cons linter-builtin-functions 'font-lock-preprocessor-face) 1249 (cons linter-builtin-functions 'font-lock-preprocessor-face)
846 ;; GNU Emacs 19 doesn't have it either 1250 ;; GNU Emacs 19 doesn't have it either
847 (if (string-match "GNU Emacs 19" emacs-version) 1251 (if (string-match "GNU Emacs 19" emacs-version)
848 (cons linter-builtin-functions 'font-lock-function-name-face) 1252 (cons linter-builtin-functions 'font-lock-keywords-face)
849 ;; Emacs 1253 ;; Emacs
850 (cons linter-builtin-functions 'font-lock-builtin-face))) 1254 (cons linter-builtin-functions 'font-lock-builtin-face)))
851 (cons linter-types 'font-lock-type-face)))))) 1255 (cons linter-types 'font-lock-type-face))))
852 1256
853 (defvar sql-mode-font-lock-keywords sql-mode-ansi-font-lock-keywords 1257 "Linter SQL keywords used by font-lock.
1258
1259 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1260 regular expressions are created during compilation by calling the
1261 function `regexp-opt'.")
1262
1263 (defvar sql-mode-ms-font-lock-keywords
1264 (let ((ms-reserved-words (eval-when-compile
1265 (concat "\\b"
1266 (regexp-opt '(
1267
1268 "absolute" "add" "all" "alter" "and" "any" "as" "asc" "authorization"
1269 "avg" "backup" "begin" "between" "break" "browse" "bulk" "by"
1270 "cascade" "case" "check" "checkpoint" "close" "clustered" "coalesce"
1271 "column" "commit" "committed" "compute" "confirm" "constraint"
1272 "contains" "containstable" "continue" "controlrow" "convert" "count"
1273 "create" "cross" "current" "current_date" "current_time"
1274 "current_timestamp" "current_user" "database" "deallocate"
1275 "declare" "default" "delete" "deny" "desc" "disk" "distinct"
1276 "distributed" "double" "drop" "dummy" "dump" "else" "end" "errlvl"
1277 "errorexit" "escape" "except" "exec" "execute" "exists" "exit" "fetch"
1278 "file" "fillfactor" "first" "floppy" "for" "foreign" "freetext"
1279 "freetexttable" "from" "full" "goto" "grant" "group" "having"
1280 "holdlock" "identity" "identity_insert" "identitycol" "if" "in"
1281 "index" "inner" "insert" "intersect" "into" "is" "isolation" "join"
1282 "key" "kill" "last" "left" "level" "like" "lineno" "load" "max" "min"
1283 "mirrorexit" "national" "next" "nocheck" "nolock" "nonclustered" "not"
1284 "null" "nullif" "of" "off" "offsets" "on" "once" "only" "open"
1285 "opendatasource" "openquery" "openrowset" "option" "or" "order"
1286 "outer" "output" "over" "paglock" "percent" "perm" "permanent" "pipe"
1287 "plan" "precision" "prepare" "primary" "print" "prior" "privileges"
1288 "proc" "procedure" "processexit" "public" "raiserror" "read"
1289 "readcommitted" "readpast" "readtext" "readuncommitted" "reconfigure"
1290 "references" "relative" "repeatable" "repeatableread" "replication"
1291 "restore" "restrict" "return" "revoke" "right" "rollback" "rowcount"
1292 "rowguidcol" "rowlock" "rule" "save" "schema" "select" "serializable"
1293 "session_user" "set" "shutdown" "some" "statistics" "sum"
1294 "system_user" "table" "tablock" "tablockx" "tape" "temp" "temporary"
1295 "textsize" "then" "to" "top" "tran" "transaction" "trigger" "truncate"
1296 "tsequal" "uncommitted" "union" "unique" "update" "updatetext"
1297 "updlock" "use" "user" "values" "view" "waitfor" "when" "where"
1298 "while" "with" "work" "writetext"
1299 "collate" "function" "openxml" "returns"
1300
1301 ) t) "\\b")))
1302 (ms-types (eval-when-compile
1303 (concat "\\b"
1304 (regexp-opt '(
1305
1306 "binary" "bit" "char" "character" "cursor" "datetime" "dec" "decimal"
1307 "double" "float" "image" "int" "integer" "money" "national" "nchar"
1308 "ntext" "numeric" "numeric" "nvarchar" "precision" "real"
1309 "smalldatetime" "smallint" "smallmoney" "text" "timestamp" "tinyint"
1310 "uniqueidentifier" "varbinary" "varchar" "varying"
1311
1312 ) t) "\\b")))
1313
1314 (ms-vars "\\b@[a-zA-Z0-9_]*\\b")
1315
1316 (ms-builtin-functions (eval-when-compile
1317 (concat "\\b"
1318 (regexp-opt '(
1319 ;; Misc MS builtin functions
1320
1321 "@@connections" "@@cpu_busy" "@@cursor_rows" "@@datefirst" "@@dbts"
1322 "@@error" "@@fetch_status" "@@identity" "@@idle" "@@io_busy"
1323 "@@langid" "@@language" "@@lock_timeout" "@@max_connections"
1324 "@@max_precision" "@@nestlevel" "@@options" "@@pack_received"
1325 "@@pack_sent" "@@packet_errors" "@@procid" "@@remserver" "@@rowcount"
1326 "@@servername" "@@servicename" "@@spid" "@@textsize" "@@timeticks"
1327 "@@total_errors" "@@total_read" "@@total_write" "@@trancount"
1328 "@@version" "abs" "acos" "and" "app_name" "ascii" "asin" "atan" "atn2"
1329 "avg" "case" "cast" "ceiling" "char" "charindex" "coalesce"
1330 "col_length" "col_name" "columnproperty" "containstable" "convert"
1331 "cos" "cot" "count" "current_timestamp" "current_user" "cursor_status"
1332 "databaseproperty" "datalength" "dateadd" "datediff" "datename"
1333 "datepart" "day" "db_id" "db_name" "degrees" "difference" "exp"
1334 "file_id" "file_name" "filegroup_id" "filegroup_name"
1335 "filegroupproperty" "fileproperty" "floor" "formatmessage"
1336 "freetexttable" "fulltextcatalogproperty" "fulltextserviceproperty"
1337 "getansinull" "getdate" "grouping" "host_id" "host_name" "ident_incr"
1338 "ident_seed" "identity" "index_col" "indexproperty" "is_member"
1339 "is_srvrolemember" "isdate" "isnull" "isnumeric" "left" "len" "log"
1340 "log10" "lower" "ltrim" "max" "min" "month" "nchar" "newid" "nullif"
1341 "object_id" "object_name" "objectproperty" "openquery" "openrowset"
1342 "parsename" "patindex" "patindex" "permissions" "pi" "power"
1343 "quotename" "radians" "rand" "replace" "replicate" "reverse" "right"
1344 "round" "rtrim" "session_user" "sign" "sin" "soundex" "space" "sqrt"
1345 "square" "stats_date" "stdev" "stdevp" "str" "stuff" "substring" "sum"
1346 "suser_id" "suser_name" "suser_sid" "suser_sname" "system_user" "tan"
1347 "textptr" "textvalid" "typeproperty" "unicode" "upper" "user"
1348 "user_id" "user_name" "var" "varp" "year"
1349
1350 ) t) "\\b")))
1351
1352 (ms-config-commands
1353 (eval-when-compile
1354 (concat "^\\(\\(set\\s-+\\("
1355 (regexp-opt '(
1356
1357 "datefirst" "dateformat" "deadlock_priority" "lock_timeout"
1358 "concat_null_yields_null" "cursor_close_on_commit"
1359 "disable_def_cnst_chk" "fips_flagger" "identity_insert" "language"
1360 "offsets" "quoted_identifier" "arithabort" "arithignore" "fmtonly"
1361 "nocount" "noexec" "numeric_roundabort" "parseonly"
1362 "query_governor_cost_limit" "rowcount" "textsize" "ansi_defaults"
1363 "ansi_null_dflt_off" "ansi_null_dflt_on" "ansi_nulls" "ansi_padding"
1364 "ansi_warnings" "forceplan" "showplan_all" "showplan_text"
1365 "statistics" "implicit_transactions" "remote_proc_transactions"
1366 "transaction" "xact_abort"
1367
1368 ) t)
1369 "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$"))))
1370
1371 (list (cons ms-config-commands 'font-lock-doc-face)
1372 (cons ms-reserved-words 'font-lock-keyword-face)
1373 ;; XEmacs doesn't have 'font-lock-builtin-face
1374 (if (string-match "XEmacs\\|Lucid" emacs-version)
1375 (cons ms-builtin-functions 'font-lock-preprocessor-face)
1376 ;; Emacs
1377 (cons ms-builtin-functions 'font-lock-builtin-face))
1378 (cons ms-vars 'font-lock-variable-name-face)
1379 (cons ms-types 'font-lock-type-face)))
1380
1381 "Microsoft SQLServer SQL keywords used by font-lock.
1382
1383 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1384 regular expressions are created during compilation by calling the
1385 function `regexp-opt'. Therefore, take a look at the source before
1386 you define your own sql-mode-ms-font-lock-keywords.")
1387
1388 (defvar sql-mode-sybase-font-lock-keywords sql-mode-ansi-font-lock-keywords
1389 "Sybase SQL keywords used by font-lock.
1390
1391 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1392 regular expressions are created during compilation by calling the
1393 function `regexp-opt'. Therefore, take a look at the source before
1394 you define your own sql-mode-sybase-font-lock-keywords.")
1395
1396 (defvar sql-mode-informix-font-lock-keywords sql-mode-ansi-font-lock-keywords
1397 "Informix SQL keywords used by font-lock.
1398
1399 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1400 regular expressions are created during compilation by calling the
1401 function `regexp-opt'. Therefore, take a look at the source before
1402 you define your own sql-mode-informix-font-lock-keywords.")
1403
1404 (defvar sql-mode-interbase-font-lock-keywords sql-mode-ansi-font-lock-keywords
1405 "Interbase SQL keywords used by font-lock.
1406
1407 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1408 regular expressions are created during compilation by calling the
1409 function `regexp-opt'. Therefore, take a look at the source before
1410 you define your own sql-mode-interbase-font-lock-keywords.")
1411
1412 (defvar sql-mode-ingres-font-lock-keywords sql-mode-ansi-font-lock-keywords
1413 "Ingres SQL keywords used by font-lock.
1414
1415 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1416 regular expressions are created during compilation by calling the
1417 function `regexp-opt'. Therefore, take a look at the source before
1418 you define your own sql-mode-interbase-font-lock-keywords.")
1419
1420 (defvar sql-mode-solid-font-lock-keywords sql-mode-ansi-font-lock-keywords
1421 "Solid SQL keywords used by font-lock.
1422
1423 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1424 regular expressions are created during compilation by calling the
1425 function `regexp-opt'. Therefore, take a look at the source before
1426 you define your own sql-mode-solid-font-lock-keywords.")
1427
1428 (defvar sql-mode-mysql-font-lock-keywords sql-mode-ansi-font-lock-keywords
1429 "MySQL SQL keywords used by font-lock.
1430
1431 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1432 regular expressions are created during compilation by calling the
1433 function `regexp-opt'. Therefore, take a look at the source before
1434 you define your own sql-mode-mysql-font-lock-keywords.")
1435
1436 (defvar sql-mode-sqlite-font-lock-keywords sql-mode-ansi-font-lock-keywords
1437 "SQLite SQL keywords used by font-lock.
1438
1439 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1440 regular expressions are created during compilation by calling the
1441 function `regexp-opt'. Therefore, take a look at the source before
1442 you define your own sql-mode-sqlite-font-lock-keywords.")
1443
1444 (defvar sql-mode-db2-font-lock-keywords sql-mode-ansi-font-lock-keywords
1445 "DB2 SQL keywords used by font-lock.
1446
1447 This variable is used by `sql-mode' and `sql-interactive-mode'. The
1448 regular expressions are created during compilation by calling the
1449 function `regexp-opt'. Therefore, take a look at the source before
1450 you define your own sql-mode-db2-font-lock-keywords.")
1451
1452 (defvar sql-mode-font-lock-keywords nil
854 "SQL keywords used by font-lock. 1453 "SQL keywords used by font-lock.
855 1454
856 This variable defaults to `sql-mode-ansi-font-lock-keywords'. This is 1455 Setting this variable directly no longer has any affect. Use
857 used for the default `font-lock-defaults' value in `sql-mode'. This 1456 `sql-product' and `sql-add-product-keywords' to control the
858 can be changed by some entry functions to provide more hilighting.") 1457 highlighting rules in sql-mode.")
859 1458
860 1459
861 1460
1461 ;;; SQL Product support functions
1462
1463 (defun sql-product-feature (feature &optional product)
1464 "Lookup `feature' needed to support the current SQL product.
1465
1466 See \[sql-product-support] for a list of products and supported features."
1467 (cadr
1468 (memq feature
1469 (assoc (or product sql-product)
1470 sql-product-support))))
1471
1472 (defun sql-product-font-lock (keywords-only imenu)
1473 "Sets `font-lock-defaults' and `font-lock-keywords' based on
1474 the product-specific keywords and syntax-alists defined in
1475 `sql-product-support'."
1476 (let
1477 ;; Get the product-specific syntax-alist.
1478 ((syntax-alist
1479 (append
1480 (sql-product-feature :syntax-alist)
1481 '((?_ . "w") (?. . "w")))))
1482
1483 ;; Get the product-specific keywords.
1484 (setq sql-mode-font-lock-keywords
1485 (append
1486 (eval (sql-product-feature :font-lock))
1487 (list sql-mode-font-lock-object-name)))
1488
1489 ;; Setup font-lock. (What is the minimum we should have to do
1490 ;; here?)
1491 (setq font-lock-set-defaults nil
1492 font-lock-keywords sql-mode-font-lock-keywords
1493 font-lock-defaults (list 'sql-mode-font-lock-keywords
1494 keywords-only t syntax-alist))
1495
1496 ;; Setup imenu; it needs the same syntax-alist.
1497 (when imenu
1498 (setq imenu-syntax-alist syntax-alist))))
1499
1500 ;;;###autoload
1501 (defun sql-add-product-keywords (product keywords)
1502 "Append a `font-lock-keywords' entry to the existing entries defined
1503 for the specified `product'."
1504
1505 (let ((font-lock (sql-product-feature :font-lock product)))
1506 (set font-lock (append (eval font-lock) (list keywords)))))
1507
1508
1509
862 ;;; Functions to switch highlighting 1510 ;;; Functions to switch highlighting
863 1511
1512 (defun sql-highlight-product ()
1513 "Turns on the appropriate font highlighting for the SQL product
1514 selected."
1515
1516 (when (eq major-mode 'sql-mode)
1517 ;; Setup font-lock
1518 (sql-product-font-lock nil t)
1519
1520 ;; Force fontification, if its enabled.
1521 (if font-lock-mode
1522 (font-lock-fontify-buffer))
1523
1524 ;; Set the mode name to include the product.
1525 (setq mode-name (concat "SQL[" (prin1-to-string sql-product) "]"))))
1526
1527 (defun sql-set-product (product)
1528 "Set `sql-product' to product and enable appropriate
1529 highlighting."
1530 (interactive "SEnter SQL product: ")
1531 (when (not (assoc product sql-product-support))
1532 (error "SQL product %s is not supported; treated as ANSI" product)
1533 (setq product 'ansi))
1534
1535 ;; Save product setting and fontify.
1536 (setq sql-product product)
1537 (sql-highlight-product))
1538
864 (defun sql-highlight-oracle-keywords () 1539 (defun sql-highlight-oracle-keywords ()
865 "Highlight Oracle keywords. 1540 "Highlight Oracle keywords."
866 Basically, this just sets `font-lock-keywords' appropriately." 1541 (interactive)
867 (interactive) 1542 (sql-set-product 'oracle))
868 (setq font-lock-keywords sql-mode-oracle-font-lock-keywords)
869 (font-lock-fontify-buffer))
870 1543
871 (defun sql-highlight-postgres-keywords () 1544 (defun sql-highlight-postgres-keywords ()
872 "Highlight Postgres keywords. 1545 "Highlight Postgres keywords."
873 Basically, this just sets `font-lock-keywords' appropriately." 1546 (interactive)
874 (interactive) 1547 (sql-set-product 'postgres))
875 (setq font-lock-keywords sql-mode-postgres-font-lock-keywords)
876 (font-lock-fontify-buffer))
877 1548
878 (defun sql-highlight-linter-keywords () 1549 (defun sql-highlight-linter-keywords ()
879 "Highlight LINTER keywords. 1550 "Highlight LINTER keywords."
880 Basically, this just sets `font-lock-keywords' appropriately." 1551 (interactive)
881 (interactive) 1552 (sql-set-product 'linter))
882 (setq font-lock-keywords sql-mode-linter-font-lock-keywords) 1553
883 (font-lock-fontify-buffer)) 1554 (defun sql-highlight-ms-keywords ()
1555 "Highlight Microsoft SQLServer keywords."
1556 (interactive)
1557 (sql-set-product 'ms))
884 1558
885 (defun sql-highlight-ansi-keywords () 1559 (defun sql-highlight-ansi-keywords ()
886 "Highlight ANSI SQL keywords. 1560 "Highlight ANSI SQL keywords."
887 Basically, this just sets `font-lock-keywords' appropriately." 1561 (interactive)
888 (interactive) 1562 (sql-set-product 'ansi))
889 (setq font-lock-keywords sql-mode-ansi-font-lock-keywords) 1563
890 (font-lock-fontify-buffer)) 1564 (defun sql-highlight-sybase-keywords ()
1565 "Highlight Sybase SQL keywords."
1566 (interactive)
1567 (sql-set-product 'sybase))
1568
1569 (defun sql-highlight-informix-keywords ()
1570 "Highlight Informix SQL keywords."
1571 (interactive)
1572 (sql-set-product 'informix))
1573
1574 (defun sql-highlight-interbase-keywords ()
1575 "Highlight Interbase SQL keywords."
1576 (interactive)
1577 (sql-set-product 'interbase))
1578
1579 (defun sql-highlight-ingres-keywords ()
1580 "Highlight Ingres SQL keywords."
1581 (interactive)
1582 (sql-set-product 'ingres))
1583
1584 (defun sql-highlight-solid-keywords ()
1585 "Highlight Solid SQL keywords."
1586 (interactive)
1587 (sql-set-product 'solid))
1588
1589 (defun sql-highlight-mysql-keywords ()
1590 "Highlight MySQL SQL keywords."
1591 (interactive)
1592 (sql-set-product 'mysql))
1593
1594 (defun sql-highlight-sqlite-keywords ()
1595 "Highlight SQLite SQL keywords."
1596 (interactive)
1597 (sql-set-product 'sqlite))
1598
1599 (defun sql-highlight-db2-keywords ()
1600 "Highlight DB2 SQL keywords."
1601 (interactive)
1602 (sql-set-product 'db2))
891 1603
892 1604
893 1605
894 ;;; Compatibility functions 1606 ;;; Compatibility functions
895 1607
951 Oracle: \\[sql-oracle] 1663 Oracle: \\[sql-oracle]
952 Informix: \\[sql-informix] 1664 Informix: \\[sql-informix]
953 Sybase: \\[sql-sybase] 1665 Sybase: \\[sql-sybase]
954 Ingres: \\[sql-ingres] 1666 Ingres: \\[sql-ingres]
955 Microsoft: \\[sql-ms] 1667 Microsoft: \\[sql-ms]
1668 DB2: \\[sql-db2]
956 Interbase: \\[sql-interbase] 1669 Interbase: \\[sql-interbase]
957 Linter: \\[sql-linter] 1670 Linter: \\[sql-linter]
958 1671
959 But we urge you to choose a free implementation instead of these. 1672 But we urge you to choose a free implementation instead of these.
960 1673
997 1710
998 Parameter WHAT is a list of the arguments passed to this function. 1711 Parameter WHAT is a list of the arguments passed to this function.
999 The function asks for the username if WHAT contains symbol `user', for 1712 The function asks for the username if WHAT contains symbol `user', for
1000 the password if it contains symbol `password', for the server if it 1713 the password if it contains symbol `password', for the server if it
1001 contains symbol `server', and for the database if it contains symbol 1714 contains symbol `server', and for the database if it contains symbol
1002 `database'. 1715 `database'. The members of WHAT are processed in the order in which
1716 they are provided.
1003 1717
1004 In order to ask the user for username, password and database, call the 1718 In order to ask the user for username, password and database, call the
1005 function like this: (sql-get-login 'user 'password 'database)." 1719 function like this: (sql-get-login 'user 'password 'database)."
1006 (interactive) 1720 (interactive)
1007 (if (memq 'user what) 1721 (while what
1722 (cond
1723 ((eq (car what) 'user) ; user
1008 (setq sql-user 1724 (setq sql-user
1009 (read-from-minibuffer "User: " sql-user nil nil 1725 (read-from-minibuffer "User: " sql-user nil nil
1010 sql-user-history))) 1726 sql-user-history)))
1011 (if (memq 'password what) 1727 ((eq (car what) 'password) ; password
1012 (setq sql-password 1728 (setq sql-password
1013 (sql-read-passwd "Password: " sql-password))) 1729 (sql-read-passwd "Password: " sql-password)))
1014 (if (memq 'server what) 1730 ((eq (car what) 'server) ; server
1015 (setq sql-server 1731 (setq sql-server
1016 (read-from-minibuffer "Server: " sql-server nil nil 1732 (read-from-minibuffer "Server: " sql-server nil nil
1017 sql-server-history))) 1733 sql-server-history)))
1018 (if (memq 'database what) 1734 ((eq (car what) 'database) ; database
1019 (setq sql-database 1735 (setq sql-database
1020 (read-from-minibuffer "Database: " sql-database nil nil 1736 (read-from-minibuffer "Database: " sql-database nil nil
1021 sql-database-history)))) 1737 sql-database-history))))
1738 (setq what (cdr what))))
1022 1739
1023 (defun sql-find-sqli-buffer () 1740 (defun sql-find-sqli-buffer ()
1024 "Return the current default SQLi buffer or nil. 1741 "Return the current default SQLi buffer or nil.
1025 In order to qualify, the SQLi buffer must be alive, 1742 In order to qualify, the SQLi buffer must be alive,
1026 be in `sql-interactive-mode' and have a process." 1743 be in `sql-interactive-mode' and have a process."
1285 (use-local-map sql-mode-map) 2002 (use-local-map sql-mode-map)
1286 (if sql-mode-menu 2003 (if sql-mode-menu
1287 (easy-menu-add sql-mode-menu)); XEmacs 2004 (easy-menu-add sql-mode-menu)); XEmacs
1288 (set-syntax-table sql-mode-syntax-table) 2005 (set-syntax-table sql-mode-syntax-table)
1289 (make-local-variable 'font-lock-defaults) 2006 (make-local-variable 'font-lock-defaults)
1290 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try 2007 (make-local-variable 'sql-mode-font-lock-keywords)
1291 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
1292 ;; will have just one quote. Therefore syntactic hilighting is
1293 ;; disabled for interactive buffers. `_' and `.' are considered part
1294 ;; of words.
1295 (setq font-lock-defaults '(sql-mode-font-lock-keywords
1296 nil t ((?_ . "w") (?. . "w"))))
1297 (make-local-variable 'comment-start) 2008 (make-local-variable 'comment-start)
1298 (setq comment-start "--") 2009 (setq comment-start "--")
1299 ;; Make each buffer in sql-mode remember the "current" SQLi buffer. 2010 ;; Make each buffer in sql-mode remember the "current" SQLi buffer.
1300 (make-local-variable 'sql-buffer) 2011 (make-local-variable 'sql-buffer)
1301 ;; Add imenu support for sql-mode. Note that imenu-generic-expression 2012 ;; Add imenu support for sql-mode. Note that imenu-generic-expression
1302 ;; is buffer-local, so we don't need a local-variable for it. SQL is 2013 ;; is buffer-local, so we don't need a local-variable for it. SQL is
1303 ;; case-insensitive, that's why we have to set imenu-case-fold-search. 2014 ;; case-insensitive, that's why we have to set imenu-case-fold-search.
1304 ;; imenu-syntax-alist makes sure that `_' is considered part of object
1305 ;; names.
1306 (setq imenu-generic-expression sql-imenu-generic-expression 2015 (setq imenu-generic-expression sql-imenu-generic-expression
1307 imenu-case-fold-search t 2016 imenu-case-fold-search t)
1308 imenu-syntax-alist '(("_" . "w")))
1309 ;; Make `sql-send-paragraph' work on paragraphs that contain indented 2017 ;; Make `sql-send-paragraph' work on paragraphs that contain indented
1310 ;; lines. 2018 ;; lines.
1311 (make-local-variable 'paragraph-separate) 2019 (make-local-variable 'paragraph-separate)
1312 (make-local-variable 'paragraph-start) 2020 (make-local-variable 'paragraph-start)
1313 (setq paragraph-separate "[\f]*$" 2021 (setq paragraph-separate "[\f]*$"
1314 paragraph-start "[\n\f]") 2022 paragraph-start "[\n\f]")
1315 ;; Abbrevs 2023 ;; Abbrevs
1316 (setq local-abbrev-table sql-mode-abbrev-table) 2024 (setq local-abbrev-table sql-mode-abbrev-table)
1317 (setq abbrev-all-caps 1) 2025 (setq abbrev-all-caps 1)
1318 ;; Run hook 2026 ;; Run hook
1319 (run-hooks 'sql-mode-hook)) 2027 (run-hooks 'sql-mode-hook)
2028 ;; Catch changes to sql-product and highlight accordingly
2029 (sql-highlight-product)
2030 (add-hook 'hack-local-variables-hook 'sql-highlight-product t t))
1320 2031
1321 2032
1322 2033
1323 ;;; SQL interactive mode 2034 ;;; SQL interactive mode
1324 2035
1391 you entered, right above the output it created. 2102 you entered, right above the output it created.
1392 2103
1393 \(setq comint-output-filter-functions 2104 \(setq comint-output-filter-functions
1394 \(function (lambda (STR) (comint-show-output))))" 2105 \(function (lambda (STR) (comint-show-output))))"
1395 (comint-mode) 2106 (comint-mode)
1396 (setq comint-prompt-regexp sql-prompt-regexp) 2107 ;; Get the `sql-product' for this interactive session.
1397 (setq left-margin sql-prompt-length) 2108 (set (make-local-variable 'sql-product)
2109 (or sql-interactive-product
2110 sql-product))
2111 ;; Setup the mode.
1398 (setq major-mode 'sql-interactive-mode) 2112 (setq major-mode 'sql-interactive-mode)
1399 (setq mode-name "SQLi") 2113 (setq mode-name (concat "SQLi[" (prin1-to-string sql-product) "]"))
1400 (use-local-map sql-interactive-mode-map) 2114 (use-local-map sql-interactive-mode-map)
1401 (if sql-interactive-mode-menu 2115 (if sql-interactive-mode-menu
1402 (easy-menu-add sql-interactive-mode-menu)); XEmacs 2116 (easy-menu-add sql-interactive-mode-menu)) ; XEmacs
1403 (set-syntax-table sql-mode-syntax-table) 2117 (set-syntax-table sql-mode-syntax-table)
2118 (make-local-variable 'sql-mode-font-lock-keywords)
1404 (make-local-variable 'font-lock-defaults) 2119 (make-local-variable 'font-lock-defaults)
1405 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try 2120 ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
1406 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column 2121 ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
1407 ;; will have just one quote. Therefore syntactic hilighting is 2122 ;; will have just one quote. Therefore syntactic hilighting is
1408 ;; disabled for interactive buffers. `_' and `.' are considered part 2123 ;; disabled for interactive buffers. No imenu support.
1409 ;; of words. 2124 (sql-product-font-lock t nil)
1410 (setq font-lock-defaults '(sql-mode-font-lock-keywords
1411 t t ((?_ . "w") (?. . "w"))))
1412 ;; Enable commenting and uncommenting of the region. 2125 ;; Enable commenting and uncommenting of the region.
1413 (make-local-variable 'comment-start) 2126 (make-local-variable 'comment-start)
1414 (setq comment-start "--") 2127 (setq comment-start "--")
1415 ;; Abbreviation table init and case-insensitive. It is not activatet 2128 ;; Abbreviation table init and case-insensitive. It is not activated
1416 ;; by default. 2129 ;; by default.
1417 (setq local-abbrev-table sql-mode-abbrev-table) 2130 (setq local-abbrev-table sql-mode-abbrev-table)
1418 (setq abbrev-all-caps 1) 2131 (setq abbrev-all-caps 1)
1419 ;; Exiting the process will call sql-stop. 2132 ;; Exiting the process will call sql-stop.
1420 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop) 2133 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop)
2134 ;; Create a usefull name for renaming this buffer later.
2135 (make-local-variable 'sql-alternate-buffer-name)
2136 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name))
2137 ;; User stuff. Initialize before the hook.
2138 (set (make-local-variable 'sql-prompt-regexp)
2139 (sql-product-feature :sqli-prompt-regexp))
2140 (set (make-local-variable 'sql-prompt-length)
2141 (sql-product-feature :sqli-prompt-length))
2142 (make-local-variable 'sql-input-ring-separator)
2143 (make-local-variable 'sql-input-ring-file-name)
2144 ;; Run hook.
2145 (run-hooks 'sql-interactive-mode-hook)
2146 ;; Set comint based on user overrides.
2147 (setq comint-prompt-regexp sql-prompt-regexp)
2148 (setq left-margin sql-prompt-length)
1421 ;; People wanting a different history file for each 2149 ;; People wanting a different history file for each
1422 ;; buffer/process/client/whatever can change separator and file-name 2150 ;; buffer/process/client/whatever can change separator and file-name
1423 ;; on the sql-interactive-mode-hook. 2151 ;; on the sql-interactive-mode-hook.
1424 (setq comint-input-ring-separator sql-input-ring-separator 2152 (setq comint-input-ring-separator sql-input-ring-separator
1425 comint-input-ring-file-name sql-input-ring-file-name) 2153 comint-input-ring-file-name sql-input-ring-file-name)
1426 ;; Create a usefull name for renaming this buffer later.
1427 (make-local-variable 'sql-alternate-buffer-name)
1428 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name))
1429 ;; User stuff.
1430 (run-hooks 'sql-interactive-mode-hook)
1431 ;; Calling the hook before calling comint-read-input-ring allows users 2154 ;; Calling the hook before calling comint-read-input-ring allows users
1432 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook. 2155 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook.
1433 (comint-read-input-ring t)) 2156 (comint-read-input-ring t))
1434 2157
1435 (defun sql-stop (process event) 2158 (defun sql-stop (process event)
1449 2172
1450 2173
1451 ;;; Entry functions for different SQL interpreters. 2174 ;;; Entry functions for different SQL interpreters.
1452 2175
1453 ;;;###autoload 2176 ;;;###autoload
2177 (defun sql-product-interactive (&optional product)
2178 "Run product interpreter as an inferior process.
2179
2180 If buffer `*SQL*' exists but no process is running, make a new process.
2181 If buffer exists and a process is running, just switch to buffer
2182 `*SQL*'.
2183
2184 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
2185 (interactive)
2186 (setq product (or product sql-product))
2187 (when (sql-product-feature :sqli-connect product)
2188 (if (comint-check-proc "*SQL*")
2189 (pop-to-buffer "*SQL*")
2190 ;; Get credentials.
2191 (apply 'sql-get-login (sql-product-feature :sqli-login product))
2192 ;; Connect to database.
2193 (message "Login...")
2194 (funcall (sql-product-feature :sqli-connect product))
2195 ;; Set SQLi mode.
2196 (setq sql-interactive-product product)
2197 (setq sql-buffer (current-buffer))
2198 (sql-interactive-mode)
2199 ;; All done.
2200 (message "Login...done")
2201 (pop-to-buffer sql-buffer))))
2202
2203 ;;;###autoload
1454 (defun sql-oracle () 2204 (defun sql-oracle ()
1455 "Run sqlplus by Oracle as an inferior process. 2205 "Run sqlplus by Oracle as an inferior process.
1456 2206
1457 If buffer `*SQL*' exists but no process is running, make a new process. 2207 If buffer `*SQL*' exists but no process is running, make a new process.
1458 If buffer exists and a process is running, just switch to buffer 2208 If buffer exists and a process is running, just switch to buffer
1473 The default comes from `process-coding-system-alist' and 2223 The default comes from `process-coding-system-alist' and
1474 `default-process-coding-system'. 2224 `default-process-coding-system'.
1475 2225
1476 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2226 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1477 (interactive) 2227 (interactive)
1478 (if (comint-check-proc "*SQL*") 2228 (sql-product-interactive 'oracle))
1479 (pop-to-buffer "*SQL*") 2229
1480 (sql-get-login 'user 'password 'database) 2230 (defun sql-connect-oracle ()
1481 (message "Login...") 2231 "Create comint buffer and connect to Oracle using the login
1482 ;; Produce user/password@database construct. Password without user 2232 parameters and command options."
1483 ;; is meaningless; database without user/password is meaningless, 2233 ;; Produce user/password@database construct. Password without user
1484 ;; because "@param" will ask sqlplus to interpret the script 2234 ;; is meaningless; database without user/password is meaningless,
1485 ;; "param". 2235 ;; because "@param" will ask sqlplus to interpret the script
1486 (let ((parameter nil)) 2236 ;; "param".
1487 (if (not (string= "" sql-user)) 2237 (let ((parameter nil))
1488 (if (not (string= "" sql-password)) 2238 (if (not (string= "" sql-user))
1489 (setq parameter (concat sql-user "/" sql-password)) 2239 (if (not (string= "" sql-password))
1490 (setq parameter sql-user))) 2240 (setq parameter (concat sql-user "/" sql-password))
1491 (if (and parameter (not (string= "" sql-database))) 2241 (setq parameter sql-user)))
1492 (setq parameter (concat parameter "@" sql-database))) 2242 (if (and parameter (not (string= "" sql-database)))
1493 (if parameter 2243 (setq parameter (concat parameter "@" sql-database)))
1494 (setq parameter (nconc (list parameter) sql-oracle-options)) 2244 (if parameter
1495 (setq parameter sql-oracle-options)) 2245 (setq parameter (nconc (list parameter) sql-oracle-options))
1496 (if parameter 2246 (setq parameter sql-oracle-options))
1497 (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil 2247 (if parameter
1498 parameter)) 2248 (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil
1499 (set-buffer (make-comint "SQL" sql-oracle-program nil)))) 2249 parameter))
1500 (setq sql-prompt-regexp "^SQL> ") 2250 (set-buffer (make-comint "SQL" sql-oracle-program nil)))
1501 (setq sql-prompt-length 5) 2251 ;; SQL*Plus is buffered on WindowsNT; this handles &placeholders.
1502 (setq sql-buffer (current-buffer))
1503 ;; set sql-mode-font-lock-keywords to something different before
1504 ;; calling sql-interactive-mode.
1505 (setq sql-mode-font-lock-keywords sql-mode-oracle-font-lock-keywords)
1506 (sql-interactive-mode)
1507 ;; If running on NT, make sure we do placeholder replacement
1508 ;; ourselves. This must come after sql-interactive-mode because all
1509 ;; local variables will be killed, there.
1510 (if (eq window-system 'w32) 2252 (if (eq window-system 'w32)
1511 (setq comint-input-sender 'sql-query-placeholders-and-send)) 2253 (setq comint-input-sender 'sql-query-placeholders-and-send))))
1512 (message "Login...done")
1513 (pop-to-buffer sql-buffer)))
1514 2254
1515 2255
1516 2256
1517 ;;;###autoload 2257 ;;;###autoload
1518 (defun sql-sybase () 2258 (defun sql-sybase ()
1537 The default comes from `process-coding-system-alist' and 2277 The default comes from `process-coding-system-alist' and
1538 `default-process-coding-system'. 2278 `default-process-coding-system'.
1539 2279
1540 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2280 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1541 (interactive) 2281 (interactive)
1542 (if (comint-check-proc "*SQL*") 2282 (sql-product-interactive 'sybase))
1543 (pop-to-buffer "*SQL*") 2283
1544 (sql-get-login 'server 'user 'password 'database) 2284 (defun sql-connect-sybase ()
1545 (message "Login...") 2285 "Create comint buffer and connect to Sybase using the login
1546 ;; Put all parameters to the program (if defined) in a list and call 2286 parameters and command options."
1547 ;; make-comint. 2287 ;; Put all parameters to the program (if defined) in a list and call
1548 (let ((params sql-sybase-options)) 2288 ;; make-comint.
1549 (if (not (string= "" sql-server)) 2289 (let ((params sql-sybase-options))
1550 (setq params (append (list "-S" sql-server) params))) 2290 (if (not (string= "" sql-server))
1551 (if (not (string= "" sql-database)) 2291 (setq params (append (list "-S" sql-server) params)))
1552 (setq params (append (list "-D" sql-database) params))) 2292 (if (not (string= "" sql-database))
1553 (if (not (string= "" sql-password)) 2293 (setq params (append (list "-D" sql-database) params)))
1554 (setq params (append (list "-P" sql-password) params))) 2294 (if (not (string= "" sql-password))
1555 (if (not (string= "" sql-user)) 2295 (setq params (append (list "-P" sql-password) params)))
1556 (setq params (append (list "-U" sql-user) params))) 2296 (if (not (string= "" sql-user))
1557 (set-buffer (apply 'make-comint "SQL" sql-sybase-program 2297 (setq params (append (list "-U" sql-user) params)))
1558 nil params))) 2298 (set-buffer (apply 'make-comint "SQL" sql-sybase-program
1559 (setq sql-prompt-regexp "^SQL> ") 2299 nil params))))
1560 (setq sql-prompt-length 5)
1561 (setq sql-buffer (current-buffer))
1562 (sql-interactive-mode)
1563 (message "Login...done")
1564 (pop-to-buffer sql-buffer)))
1565 2300
1566 2301
1567 2302
1568 ;;;###autoload 2303 ;;;###autoload
1569 (defun sql-informix () 2304 (defun sql-informix ()
1586 The default comes from `process-coding-system-alist' and 2321 The default comes from `process-coding-system-alist' and
1587 `default-process-coding-system'. 2322 `default-process-coding-system'.
1588 2323
1589 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2324 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1590 (interactive) 2325 (interactive)
1591 (if (comint-check-proc "*SQL*") 2326 (sql-product-interactive 'informix))
1592 (pop-to-buffer "*SQL*") 2327
1593 (sql-get-login 'database) 2328 (defun sql-connect-informix ()
1594 (message "Login...") 2329 "Create comint buffer and connect to Informix using the login
1595 ;; username and password are ignored. 2330 parameters and command options."
1596 (if (string= "" sql-database) 2331 ;; username and password are ignored.
1597 (set-buffer (make-comint "SQL" sql-informix-program nil)) 2332 (if (string= "" sql-database)
1598 (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-"))) 2333 (set-buffer (make-comint "SQL" sql-informix-program nil))
1599 (setq sql-prompt-regexp "^SQL> ") 2334 (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-"))))
1600 (setq sql-prompt-length 5)
1601 (setq sql-buffer (current-buffer))
1602 (sql-interactive-mode)
1603 (message "Login...done")
1604 (pop-to-buffer sql-buffer)))
1605 2335
1606 2336
1607 2337
1608 ;;;###autoload 2338 ;;;###autoload
1609 (defun sql-sqlite () 2339 (defun sql-sqlite ()
1630 The default comes from `process-coding-system-alist' and 2360 The default comes from `process-coding-system-alist' and
1631 `default-process-coding-system'. 2361 `default-process-coding-system'.
1632 2362
1633 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2363 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1634 (interactive) 2364 (interactive)
1635 (if (comint-check-proc "*SQL*") 2365 (sql-product-interactive 'sqlite))
1636 (pop-to-buffer "*SQL*") 2366
1637 (sql-get-login 'database) 2367 (defun sql-connect-sqlite ()
1638 (message "Login...") 2368 "Create comint buffer and connect to SQLite using the login
1639 ;; Put all parameters to the program (if defined) in a list and call 2369 parameters and command options."
1640 ;; make-comint. 2370 ;; Put all parameters to the program (if defined) in a list and call
1641 (let ((params)) 2371 ;; make-comint.
1642 (if (not (string= "" sql-database)) 2372 (let ((params))
1643 (setq params (append (list sql-database) params))) 2373 (if (not (string= "" sql-database))
1644 (if (not (string= "" sql-server)) 2374 (setq params (append (list sql-database) params)))
1645 (setq params (append (list (concat "--host=" sql-server)) params))) 2375 (if (not (string= "" sql-server))
1646 (if (not (string= "" sql-password)) 2376 (setq params (append (list (concat "--host=" sql-server)) params)))
1647 (setq params (append (list (concat "--password=" sql-password)) params))) 2377 (if (not (string= "" sql-password))
1648 (if (not (string= "" sql-user)) 2378 (setq params (append (list (concat "--password=" sql-password)) params)))
1649 (setq params (append (list (concat "--user=" sql-user)) params))) 2379 (if (not (string= "" sql-user))
1650 (if (not (null sql-sqlite-options)) 2380 (setq params (append (list (concat "--user=" sql-user)) params)))
1651 (setq params (append sql-sqlite-options params))) 2381 (if (not (null sql-sqlite-options))
1652 (set-buffer (apply 'make-comint "SQL" sql-sqlite-program 2382 (setq params (append sql-sqlite-options params)))
1653 nil params))) 2383 (set-buffer (apply 'make-comint "SQL" sql-sqlite-program
1654 (setq sql-prompt-regexp "^sqlite> ") 2384 nil params))))
1655 (setq sql-prompt-length 8)
1656 (setq sql-buffer (current-buffer))
1657 (sql-interactive-mode)
1658 (message "Login...done")
1659 (pop-to-buffer sql-buffer)))
1660 2385
1661 2386
1662 2387
1663 ;;;###autoload 2388 ;;;###autoload
1664 (defun sql-mysql () 2389 (defun sql-mysql ()
1685 The default comes from `process-coding-system-alist' and 2410 The default comes from `process-coding-system-alist' and
1686 `default-process-coding-system'. 2411 `default-process-coding-system'.
1687 2412
1688 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2413 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1689 (interactive) 2414 (interactive)
1690 (if (comint-check-proc "*SQL*") 2415 (sql-product-interactive 'mysql))
1691 (pop-to-buffer "*SQL*") 2416
1692 (sql-get-login 'user 'password 'database 'server) 2417 (defun sql-connect-mysql ()
1693 (message "Login...") 2418 "Create comint buffer and connect to MySQL using the login
1694 ;; Put all parameters to the program (if defined) in a list and call 2419 parameters and command options."
1695 ;; make-comint. 2420 ;; Put all parameters to the program (if defined) in a list and call
1696 (let ((params)) 2421 ;; make-comint.
1697 (if (not (string= "" sql-database)) 2422 (let ((params))
1698 (setq params (append (list sql-database) params))) 2423 (if (not (string= "" sql-database))
1699 (if (not (string= "" sql-server)) 2424 (setq params (append (list sql-database) params)))
1700 (setq params (append (list (concat "--host=" sql-server)) params))) 2425 (if (not (string= "" sql-server))
1701 (if (not (string= "" sql-password)) 2426 (setq params (append (list (concat "--host=" sql-server)) params)))
1702 (setq params (append (list (concat "--password=" sql-password)) params))) 2427 (if (not (string= "" sql-password))
1703 (if (not (string= "" sql-user)) 2428 (setq params (append (list (concat "--password=" sql-password)) params)))
1704 (setq params (append (list (concat "--user=" sql-user)) params))) 2429 (if (not (string= "" sql-user))
1705 (if (not (null sql-mysql-options)) 2430 (setq params (append (list (concat "--user=" sql-user)) params)))
1706 (setq params (append sql-mysql-options params))) 2431 (if (not (null sql-mysql-options))
1707 (set-buffer (apply 'make-comint "SQL" sql-mysql-program 2432 (setq params (append sql-mysql-options params)))
1708 nil params))) 2433 (set-buffer (apply 'make-comint "SQL" sql-mysql-program
1709 (setq sql-prompt-regexp "^mysql>") 2434 nil params))))
1710 (setq sql-prompt-length 6)
1711 (setq sql-buffer (current-buffer))
1712 (sql-interactive-mode)
1713 (message "Login...done")
1714 (pop-to-buffer sql-buffer)))
1715 2435
1716 2436
1717 2437
1718 ;;;###autoload 2438 ;;;###autoload
1719 (defun sql-solid () 2439 (defun sql-solid ()
1737 The default comes from `process-coding-system-alist' and 2457 The default comes from `process-coding-system-alist' and
1738 `default-process-coding-system'. 2458 `default-process-coding-system'.
1739 2459
1740 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2460 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1741 (interactive) 2461 (interactive)
1742 (if (comint-check-proc "*SQL*") 2462 (sql-product-interactive 'solid))
1743 (pop-to-buffer "*SQL*") 2463
1744 (sql-get-login 'user 'password 'server) 2464 (defun sql-connect-solid ()
1745 (message "Login...") 2465 "Create comint buffer and connect to Solid using the login
1746 ;; Put all parameters to the program (if defined) in a list and call 2466 parameters and command options."
1747 ;; make-comint. 2467 ;; Put all parameters to the program (if defined) in a list and call
1748 (let ((params)) 2468 ;; make-comint.
1749 ;; It only makes sense if both username and password are there. 2469 (let ((params))
1750 (if (not (or (string= "" sql-user) 2470 ;; It only makes sense if both username and password are there.
1751 (string= "" sql-password))) 2471 (if (not (or (string= "" sql-user)
1752 (setq params (append (list sql-user sql-password) params))) 2472 (string= "" sql-password)))
1753 (if (not (string= "" sql-server)) 2473 (setq params (append (list sql-user sql-password) params)))
1754 (setq params (append (list sql-server) params))) 2474 (if (not (string= "" sql-server))
1755 (set-buffer (apply 'make-comint "SQL" sql-solid-program 2475 (setq params (append (list sql-server) params)))
1756 nil params))) 2476 (set-buffer (apply 'make-comint "SQL" sql-solid-program
1757 (setq sql-prompt-regexp "^") 2477 nil params))))
1758 (setq sql-prompt-length 0)
1759 (setq sql-buffer (current-buffer))
1760 (sql-interactive-mode)
1761 (message "Login...done")
1762 (pop-to-buffer sql-buffer)))
1763 2478
1764 2479
1765 2480
1766 ;;;###autoload 2481 ;;;###autoload
1767 (defun sql-ingres () 2482 (defun sql-ingres ()
1784 The default comes from `process-coding-system-alist' and 2499 The default comes from `process-coding-system-alist' and
1785 `default-process-coding-system'. 2500 `default-process-coding-system'.
1786 2501
1787 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2502 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1788 (interactive) 2503 (interactive)
1789 (if (comint-check-proc "*SQL*") 2504 (sql-product-interactive 'ingres))
1790 (pop-to-buffer "*SQL*") 2505
1791 (sql-get-login 'database) 2506 (defun sql-connect-ingres ()
1792 (message "Login...") 2507 "Create comint buffer and connect to Ingres using the login
1793 ;; username and password are ignored. 2508 parameters and command options."
1794 (if (string= "" sql-database) 2509 ;; username and password are ignored.
1795 (set-buffer (make-comint "SQL" sql-ingres-program nil)) 2510 (if (string= "" sql-database)
1796 (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database))) 2511 (set-buffer (make-comint "SQL" sql-ingres-program nil))
1797 (setq sql-prompt-regexp "^\* ") 2512 (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database))))
1798 (setq sql-prompt-length 2)
1799 (setq sql-buffer (current-buffer))
1800 (sql-interactive-mode)
1801 (message "Login...done")
1802 (pop-to-buffer sql-buffer)))
1803 2513
1804 2514
1805 2515
1806 ;;;###autoload 2516 ;;;###autoload
1807 (defun sql-ms () 2517 (defun sql-ms ()
1808 "Run isql by Microsoft as an inferior process. 2518 "Run osql by Microsoft as an inferior process.
1809 2519
1810 If buffer `*SQL*' exists but no process is running, make a new process. 2520 If buffer `*SQL*' exists but no process is running, make a new process.
1811 If buffer exists and a process is running, just switch to buffer 2521 If buffer exists and a process is running, just switch to buffer
1812 `*SQL*'. 2522 `*SQL*'.
1813 2523
1826 The default comes from `process-coding-system-alist' and 2536 The default comes from `process-coding-system-alist' and
1827 `default-process-coding-system'. 2537 `default-process-coding-system'.
1828 2538
1829 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2539 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1830 (interactive) 2540 (interactive)
1831 (if (comint-check-proc "*SQL*") 2541 (sql-product-interactive 'ms))
1832 (pop-to-buffer "*SQL*") 2542
1833 (sql-get-login 'user 'password 'database 'server) 2543 (defun sql-connect-ms ()
1834 (message "Login...") 2544 "Create comint buffer and connect to Microsoft using the login
1835 ;; Put all parameters to the program (if defined) in a list and call 2545 parameters and command options."
1836 ;; make-comint. 2546 ;; Put all parameters to the program (if defined) in a list and call
1837 (let ((params sql-ms-options)) 2547 ;; make-comint.
1838 (if (not (string= "" sql-server)) 2548 (let ((params sql-ms-options))
2549 (if (not (string= "" sql-server))
1839 (setq params (append (list "-S" sql-server) params))) 2550 (setq params (append (list "-S" sql-server) params)))
1840 (if (not (string= "" sql-database)) 2551 (if (not (string= "" sql-database))
1841 (setq params (append (list "-d" sql-database) params))) 2552 (setq params (append (list "-d" sql-database) params)))
1842 (if (not (string= "" sql-user)) 2553 (if (not (string= "" sql-user))
1843 (setq params (append (list "-U" sql-user) params))) 2554 (setq params (append (list "-U" sql-user) params)))
1844 (if (not (string= "" sql-password)) 2555 (if (not (string= "" sql-password))
1845 (setq params (append (list "-P" sql-password) params)) 2556 (setq params (append (list "-P" sql-password) params))
1846 ;; If -P is passed to ISQL as the last argument without a password, 2557 (if (string= "" sql-user)
1847 ;; it's considered null. 2558 ;; if neither user nor password is provided, use system
1848 (setq params (append params (list "-P")))) 2559 ;; credentials.
1849 (set-buffer (apply 'make-comint "SQL" sql-ms-program 2560 (setq params (append (list "-E") params))
1850 nil params))) 2561 ;; If -P is passed to ISQL as the last argument without a
1851 (setq sql-prompt-regexp "^[0-9]*>") 2562 ;; password, it's considered null.
1852 (setq sql-prompt-length 5) 2563 (setq params (append params (list "-P")))))
1853 (setq sql-buffer (current-buffer)) 2564 (set-buffer (apply 'make-comint "SQL" sql-ms-program
1854 (sql-interactive-mode) 2565 nil params))))
1855 (message "Login...done")
1856 (pop-to-buffer sql-buffer)))
1857 2566
1858 2567
1859 2568
1860 ;;;###autoload 2569 ;;;###autoload
1861 (defun sql-postgres () 2570 (defun sql-postgres ()
1885 \(setq comint-output-filter-functions (append comint-output-filter-functions 2594 \(setq comint-output-filter-functions (append comint-output-filter-functions
1886 '(comint-strip-ctrl-m))) 2595 '(comint-strip-ctrl-m)))
1887 2596
1888 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2597 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1889 (interactive) 2598 (interactive)
1890 (if (comint-check-proc "*SQL*") 2599 (sql-product-interactive 'postgres))
1891 (pop-to-buffer "*SQL*") 2600
1892 (sql-get-login 'database 'server) 2601 (defun sql-connect-postgres ()
1893 (message "Login...") 2602 "Create comint buffer and connect to Postgres using the login
1894 ;; username and password are ignored. Mark Stosberg suggest to add 2603 parameters and command options."
1895 ;; the database at the end. Jason Beegan suggest using --pset and 2604 ;; username and password are ignored. Mark Stosberg suggest to add
1896 ;; pager=off instead of \\o|cat. The later was the solution by 2605 ;; the database at the end. Jason Beegan suggest using --pset and
1897 ;; Gregor Zych. Jason's suggestion is the default value for 2606 ;; pager=off instead of \\o|cat. The later was the solution by
1898 ;; sql-postgres-options. 2607 ;; Gregor Zych. Jason's suggestion is the default value for
1899 (let ((params sql-postgres-options)) 2608 ;; sql-postgres-options.
1900 (if (not (string= "" sql-database)) 2609 (let ((params sql-postgres-options))
1901 (setq params (append params (list sql-database)))) 2610 (if (not (string= "" sql-database))
1902 (if (not (string= "" sql-server)) 2611 (setq params (append params (list sql-database))))
1903 (setq params (append (list "-h" sql-server) params))) 2612 (if (not (string= "" sql-server))
1904 (set-buffer (apply 'make-comint "SQL" sql-postgres-program 2613 (setq params (append (list "-h" sql-server) params)))
1905 nil params))) 2614 (set-buffer (apply 'make-comint "SQL" sql-postgres-program
1906 (setq sql-prompt-regexp "^.*> *") 2615 nil params))))
1907 (setq sql-prompt-length 5)
1908 ;; This is a lousy hack to prevent psql from truncating it's output
1909 ;; and giving stupid warnings. If s.o. knows a way to prevent psql
1910 ;; from acting this way, then I would be very thankful to
1911 ;; incorporate this (Gregor Zych <zych@pool.informatik.rwth-aachen.de>)
1912 ;; (comint-send-string "*SQL*" "\\o \| cat\n")
1913 (setq sql-mode-font-lock-keywords sql-mode-postgres-font-lock-keywords)
1914 (setq sql-buffer (current-buffer))
1915 (sql-interactive-mode)
1916 (message "Login...done")
1917 (pop-to-buffer sql-buffer)))
1918 2616
1919 2617
1920 2618
1921 ;;;###autoload 2619 ;;;###autoload
1922 (defun sql-interbase () 2620 (defun sql-interbase ()
1940 The default comes from `process-coding-system-alist' and 2638 The default comes from `process-coding-system-alist' and
1941 `default-process-coding-system'. 2639 `default-process-coding-system'.
1942 2640
1943 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2641 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1944 (interactive) 2642 (interactive)
1945 (if (comint-check-proc "*SQL*") 2643 (sql-product-interactive 'interbase))
1946 (pop-to-buffer "*SQL*") 2644
1947 (sql-get-login 'user 'password 'database) 2645 (defun sql-connect-interbase ()
1948 (message "Login...") 2646 "Create comint buffer and connect to Interbase using the login
1949 ;; Put all parameters to the program (if defined) in a list and call 2647 parameters and command options."
1950 ;; make-comint. 2648 ;; Put all parameters to the program (if defined) in a list and call
1951 (let ((params sql-interbase-options)) 2649 ;; make-comint.
1952 (if (not (string= "" sql-user)) 2650 (let ((params sql-interbase-options))
1953 (setq params (append (list "-u" sql-user) params))) 2651 (if (not (string= "" sql-user))
1954 (if (not (string= "" sql-password)) 2652 (setq params (append (list "-u" sql-user) params)))
1955 (setq params (append (list "-p" sql-password) params))) 2653 (if (not (string= "" sql-password))
1956 (if (not (string= "" sql-database)) 2654 (setq params (append (list "-p" sql-password) params)))
1957 (setq params (cons sql-database params))); add to the front! 2655 (if (not (string= "" sql-database))
1958 (set-buffer (apply 'make-comint "SQL" sql-interbase-program 2656 (setq params (cons sql-database params))) ; add to the front!
1959 nil params))) 2657 (set-buffer (apply 'make-comint "SQL" sql-interbase-program
1960 (setq sql-prompt-regexp "^SQL> ") 2658 nil params))))
1961 (setq sql-prompt-length 5)
1962 (setq sql-buffer (current-buffer))
1963 (sql-interactive-mode)
1964 (message "Login...done")
1965 (pop-to-buffer sql-buffer)))
1966 2659
1967 2660
1968 2661
1969 ;;;###autoload 2662 ;;;###autoload
1970 (defun sql-db2 () 2663 (defun sql-db2 ()
1992 The default comes from `process-coding-system-alist' and 2685 The default comes from `process-coding-system-alist' and
1993 `default-process-coding-system'. 2686 `default-process-coding-system'.
1994 2687
1995 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" 2688 \(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
1996 (interactive) 2689 (interactive)
1997 (if (comint-check-proc "*SQL*") 2690 (sql-product-interactive 'db2))
1998 (pop-to-buffer "*SQL*") 2691
1999 (message "Login...") 2692 (defun sql-connect-db2 ()
2000 ;; Put all parameters to the program (if defined) in a list and call 2693 "Create comint buffer and connect to DB2 using the login
2001 ;; make-comint. 2694 parameters and command options."
2002 (set-buffer (apply 'make-comint "SQL" sql-db2-program 2695 ;; Put all parameters to the program (if defined) in a list and call
2003 nil sql-db2-options)) 2696 ;; make-comint.
2004 (setq sql-prompt-regexp "^db2 => ") 2697 (set-buffer (apply 'make-comint "SQL" sql-db2-program
2005 (setq sql-prompt-length 7) 2698 nil sql-db2-options))
2006 (setq sql-buffer (current-buffer)) 2699 ;; Properly escape newlines when DB2 is interactive.
2007 (sql-interactive-mode) 2700 (setq comint-input-sender 'sql-escape-newlines-and-send))
2008 ;; Escape newlines. This must come after sql-interactive-mode
2009 ;; because all local variables will be killed, there.
2010 (setq comint-input-sender 'sql-escape-newlines-and-send)
2011 (message "Login...done")
2012 (pop-to-buffer sql-buffer)))
2013 2701
2014 ;;;###autoload 2702 ;;;###autoload
2015 (defun sql-linter () 2703 (defun sql-linter ()
2016 "Run inl by RELEX as an inferior process. 2704 "Run inl by RELEX as an inferior process.
2017 2705
2032 an empty password. 2720 an empty password.
2033 2721
2034 The buffer is put in sql-interactive-mode, giving commands for sending 2722 The buffer is put in sql-interactive-mode, giving commands for sending
2035 input. See `sql-interactive-mode'. 2723 input. See `sql-interactive-mode'.
2036 2724
2037 To use LINTER font locking by default, put this line into your .emacs :
2038 (setq sql-mode-font-lock-keywords sql-mode-linter-font-lock-keywords)
2039
2040 \(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.)"
2041 (interactive) 2726 (interactive)
2042 (if (comint-check-proc "*SQL*") 2727 (sql-product-interactive 'linter))
2043 (pop-to-buffer "*SQL*") 2728
2044 (sql-get-login 'user 'password 'database 'server) 2729 (defun sql-connect-linter ()
2045 (message "Login...") 2730 "Create comint buffer and connect to Linter using the login
2046 ;; Put all parameters to the program (if defined) in a list and call 2731 parameters and command options."
2047 ;; make-comint. 2732 ;; Put all parameters to the program (if defined) in a list and call
2048 (let ((params sql-linter-options) (login nil) (old-mbx (getenv "LINTER_MBX"))) 2733 ;; make-comint.
2049 (if (not (string= "" sql-user)) 2734 (let ((params sql-linter-options) (login nil) (old-mbx (getenv "LINTER_MBX")))
2050 (setq login (concat sql-user "/" sql-password))) 2735 (if (not (string= "" sql-user))
2051 (setq params (append (list "-u" login) params)) 2736 (setq login (concat sql-user "/" sql-password)))
2052 (if (not (string= "" sql-server)) 2737 (setq params (append (list "-u" login) params))
2053 (setq params (append (list "-n" sql-server) params))) 2738 (if (not (string= "" sql-server))
2054 (if (string= "" sql-database) 2739 (setq params (append (list "-n" sql-server) params)))
2055 (setenv "LINTER_MBX" nil) 2740 (if (string= "" sql-database)
2056 (setenv "LINTER_MBX" sql-database)) 2741 (setenv "LINTER_MBX" nil)
2057 (set-buffer (apply 'make-comint "SQL" sql-linter-program nil 2742 (setenv "LINTER_MBX" sql-database))
2058 params)) 2743 (set-buffer (apply 'make-comint "SQL" sql-linter-program nil
2059 (setenv "LINTER_MBX" old-mbx) 2744 params))
2060 ) 2745 (setenv "LINTER_MBX" old-mbx)))
2061 (setq sql-prompt-regexp "^SQL>")
2062 (setq sql-prompt-length 4)
2063 (setq sql-buffer (current-buffer))
2064 (sql-interactive-mode)
2065 (message "Login...done")
2066 (pop-to-buffer sql-buffer)))
2067 2746
2068 2747
2069 2748
2070 (provide 'sql) 2749 (provide 'sql)
2071 2750